On 2/3/25 15:38, Bruno Haible wrote:
the
default:
break;
lines were a witness that the programmer has spent some thought
regarding the other values.
This is the first I've heard of that style. And the "default: break;"s I
put into quotearg.c are not part of that style. They were put in to
pacify gcc -Wswitch-default; see gnulib commit
b35c0cb959a95f37e766bd849a420fc7bcce712e (2006-01-22). (If these
"default: break;"s were interpreted to mean "the programmer spent some
thought", they were in some sense misleading here. :-)
I'd rather that these lines of code be omitted, as they are merely noise
to pacify GCC and now that I've found a better way to pacify GCC I'd
rather use the better way.
That being said, I'll try to keep in mind that you prefer "default:
break;"s in code you've written.
2) Future compiler versions may recognize that (+some_value), although
being an 'int', is an enumerated value under the hood.
If that happens we will need to deal with it, yes. In the meantime the
current code suffices, and -Wswitch-enum can help find plausible bugs
statically. If we can think of a better way to find the bugs that of
course would be preferable.
I got reports of a couple more places where -Wswitch-enum complains
about Gnulib code, when building correutils. For now I installed the
attached to pacify GCC there.From 1e979dfd9253b184c67623cac08abe10ac7b7aa7 Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Mon, 3 Feb 2025 16:47:36 -0800
Subject: [PATCH] c-vasnprintf: pacify -Wswitch-enum
* lib/printf-args.c (PRINTF_FETCHARGS):
Mention TYPE_NONE as being a default case.
* lib/vasnprintf.c (VASNPRINTF): Use switch (+E).
---
ChangeLog | 7 +++++++
lib/printf-args.c | 1 +
lib/vasnprintf.c | 4 ++--
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 62d6254359..6604f7fcec 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2025-02-03 Paul Eggert <[email protected]>
+
+ c-vasnprintf: pacify -Wswitch-enum
+ * lib/printf-args.c (PRINTF_FETCHARGS):
+ Mention TYPE_NONE as being a default case.
+ * lib/vasnprintf.c (VASNPRINTF): Use switch (+E).
+
2025-02-03 Bruno Haible <[email protected]>
gnulib-tool: Allow compiler warnings in Gnulib code.
diff --git a/lib/printf-args.c b/lib/printf-args.c
index 64fc37985e..e0bf87c7ee 100644
--- a/lib/printf-args.c
+++ b/lib/printf-args.c
@@ -296,6 +296,7 @@ PRINTF_FETCHARGS (va_list args, arguments *a)
}
break;
#endif
+ case TYPE_NONE:
default:
/* Unknown type. */
return -1;
diff --git a/lib/vasnprintf.c b/lib/vasnprintf.c
index 9bdea145d1..e7db39c74c 100644
--- a/lib/vasnprintf.c
+++ b/lib/vasnprintf.c
@@ -6211,7 +6211,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
}
}
- switch (type)
+ switch (+type)
{
case TYPE_LONGLONGINT:
case TYPE_ULONGLONGINT:
@@ -6507,7 +6507,7 @@ VASNPRINTF (DCHAR_T *resultbuf, size_t *lengthp,
#endif
errno = 0;
- switch (type)
+ switch (+type)
{
case TYPE_SCHAR:
{
--
2.48.1