bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

gnulib-common.m4: Make _GL_UNUSED_LABEL effective for clang


From: Bruno Haible
Subject: gnulib-common.m4: Make _GL_UNUSED_LABEL effective for clang
Date: Sun, 22 Aug 2021 22:17:01 +0200

So far, _GL_UNUSED_LABEL works for GCC but not for clang. See:

================================ foo.c ================================
int foo (int x)
{
  x += 2;
  if (x & 1)
    goto a;
b:
  x *= 3;
a:
  return x;
}
=======================================================================
$ clang -Wall -S foo.c
foo.c:6:1: warning: unused label 'b' [-Wunused-label]
b:
^~
1 warning generated.

The same definition as for GCC works, however, with clang:

================================ foo.c ================================
int foo (int x)
{
  x += 2;
  if (x & 1)
    goto a;
b:
  __attribute__ ((__unused__));
  x *= 3;
a:
  return x;
}
=======================================================================
$ clang -Wall -S foo.c
(no warning)

This patch makes _GL_UNUSED_LABEL work also for clang.


2021-08-22  Bruno Haible  <bruno@clisp.org>

        gnulib-common.m4: Make _GL_UNUSED_LABEL effective for clang.
        * m4/gnulib-common.m4 (gl_COMMON_BODY): Make _GL_UNUSED_LABEL use
        _GL_ATTRIBUTE_UNUSED also for clang.

diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index 801c7127b..8a10e5bc1 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -418,7 +418,7 @@ 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)
+#if (!defined __cplusplus || _GL_GNUC_PREREQ (4, 5)) || defined __clang__
 # define _GL_UNUSED_LABEL _GL_ATTRIBUTE_UNUSED
 #else
 # define _GL_UNUSED_LABEL






reply via email to

[Prev in Thread] Current Thread [Next in Thread]