Subject: bug#39206: warning in lib/unistr/u8-uctomb.c

From: Bruno Haible <[email-masked]>
Date: Mon, 20 Jan 2020 18:48:35 +0100

Correcting the subject.

> cc1: all warnings being treated as errors

"this statement may fall through" is a warning. *You* turned it into an
error by using -Werror or -Werror=implicit-fallthrough. It is therefore
misleading to say that there is a compilation error in lib/unistr/u8-uctomb.c.

> ../../grep/lib/unistr/u8-uctomb.c: In function 'u8_uctomb':
> ../../grep/lib/unistr/u8-uctomb.c:64:65: error: this statement may fall through [-Werror=implicit-fallthrough=]
>              case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000;
>                                                               ~~~^~~~~~~~~~
> ../../grep/lib/unistr/u8-uctomb.c:65:13: note: here
>              case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800;
>              ^~~~
> ../../grep/lib/unistr/u8-uctomb.c:65:65: error: this statement may fall through [-Werror=implicit-fallthrough=]
>              case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800;
>                                                               ~~~^~~~~~~~
> ../../grep/lib/unistr/u8-uctomb.c:66:13: note: here
>              case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0;
>              ^~~~

Fixed through the patch below.

But something is wrong with the way you build packages: This code is only seen
by the compiler when HAVE_INLINE is undefined or 0. So, apparently the
autoconfiguration determined that the compiler does not support the 'inline'
keyword. Since the compiler is clang, this finding is not true.

Most likely, you had -Werror in $CC $CFLAGS already during configuration
time. This is NOT SUPPORTED, since it causes many configure tests to produce
wrong results.

2020-01-20  Bruno Haible  <[email-masked]>

	unistr/u8-uctomb: Fix warning.
	Reported by Andreas Schwab <[email-masked]> in
	<https://lists.gnu.org/archive/html/bug-gnulib/2020-01/msg00127.html>.
	* lib/unistr/u8-uctomb.c (FALLTHROUGH): New macro.
	(u8_uctomb): Add FALLTHROUGH markers.

diff --git a/lib/unistr/u8-uctomb.c b/lib/unistr/u8-uctomb.c
index f093822..d998002 100644
--- a/lib/unistr/u8-uctomb.c
+++ b/lib/unistr/u8-uctomb.c
@@ -25,6 +25,14 @@
 /* Specification.  */
 #include "unistr.h"
 
+#ifndef FALLTHROUGH
+# if __GNUC__ < 7
+#  define FALLTHROUGH ((void) 0)
+# else
+#  define FALLTHROUGH __attribute__ ((__fallthrough__))
+# endif
+#endif
+
 #if !HAVE_INLINE
 
 int
@@ -62,7 +70,9 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n)
           switch (count) /* note: code falls through cases! */
             {
             case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000;
+              FALLTHROUGH;
             case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800;
+              FALLTHROUGH;
             case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0;
           /*case 1:*/ s[0] = uc;
             }