Paul Eggert wrote: > Also, your example used C code, but this fix doesn't affect C code. So > can we assume the real problem was with C++ code?
Yes. I tried the example both with C and C++. ================================ foo.cc ================================ int foo (int x) { x += 2; if (x & 1) goto a; b: x *= 3; a: return x; } ======================================================================== $ clang -Wall -S foo.cc foo.cc:6:1: warning: unused label 'b' [-Wunused-label] b: ^~ 1 warning generated. The same definition as for GCC works, however, with clang: ================================ foo.cc ================================ int foo (int x) { x += 2; if (x & 1) goto a; b: __attribute__ ((__unused__)); x *= 3; a: return x; } ======================================================================== $ clang -Wall -S foo.cc (no warning) > On 8/22/21 1:17 PM, Bruno Haible wrote: > > -#if !defined __cplusplus || _GL_GNUC_PREREQ (4, 5) > > +#if (!defined __cplusplus || _GL_GNUC_PREREQ (4, 5)) || defined __clang__ > > I got a bit confused by the extra parentheses, thinking that somehow GCC > and Clang differ with respect to C++. Perhaps remove the extra parens? And I got confused by this boolean expression already before, and understood it only after looking at the ChangeLog entry from 2014-06-01. This indicates that a comment is needed. This one is clearer for me. For you as well? 2021-08-22 Bruno Haible <br...@clisp.org> gnulib-common.m4: Clarify logic behind _GL_UNUSED_LABEL. Reported by Paul Eggert. * m4/gnulib-common.m4 (gl_COMMON_BODY): Add comment and write the condition in a way that is close to the comment. diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index 8a10e5bc1..639fa8567 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -418,7 +418,9 @@ AC_DEFUN([gl_COMMON_BODY], [ immediately preceding label is not used. The compiler should not warn if the label is not used. */ /* Applies to: label (both in C and C++). */ -#if (!defined __cplusplus || _GL_GNUC_PREREQ (4, 5)) || defined __clang__ +/* Note that g++ < 4.5 does not support the '__attribute__ ((__unused__)) ;' + syntax. But clang does. */ +#if !(defined __cplusplus && !_GL_GNUC_PREREQ (4, 5)) || defined __clang__ # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED #else # define _GL_UNUSED_LABEL