]> Savannah Git Hosting - gnulib.git/commitdiff
Avoid clang warnings regarding [[__maybe_unused__]].
authorBruno Haible <bruno@clisp.org>
Sat, 28 Jan 2023 08:33:12 +0000 (09:33 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 10 Feb 2023 02:19:07 +0000 (03:19 +0100)
* m4/gnulib-common.m4 (gl_COMMON_BODY): For clang versions ≥ 6, < 10,
in C++ mode, ignore the __has_c_attribute value and define
_GL_ATTRIBUTE_MAYBE_UNUSED to __attribute__ ((__unused__)), not
[[__maybe_unused__]].

ChangeLog
m4/gnulib-common.m4

index 3833faffb78e3018d542bd99fdc3449e91b4f98c..088a18bdad8edf4e81ac2561c4293bc0317addf8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2023-01-28  Bruno Haible  <bruno@clisp.org>
+
+       Avoid clang warnings regarding [[__maybe_unused__]].
+       * m4/gnulib-common.m4 (gl_COMMON_BODY): For clang versions ≥ 6, < 10,
+       in C++ mode, ignore the __has_c_attribute value and define
+       _GL_ATTRIBUTE_MAYBE_UNUSED to __attribute__ ((__unused__)), not
+       [[__maybe_unused__]].
+
 2023-01-27  Bruno Haible  <bruno@clisp.org>
 
        stddef: Fix test-stddef compilation error on FreeBSD 12/x86.
index facc3404fa4e174d2591e33fd7f81a8070f5aea3..893465c02ee7899653aff1e870ef1ba2fc06b3d5 100644 (file)
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 75a
+# gnulib-common.m4 serial 75b
 dnl Copyright (C) 2007-2023 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -351,9 +351,15 @@ AC_DEFUN([gl_COMMON_BODY], [
    in C++ also: class.  */
 /* In C++ and C23, this is spelled [[__maybe_unused__]].
    GCC's syntax is __attribute__ ((__unused__)).
-   clang supports both syntaxes.  */
+   clang supports both syntaxes.  Except that with clang ≥ 6, < 10, in C++ mode,
+   __has_c_attribute (__maybe_unused__) yields true but the use of
+   [[__maybe_unused__]] nevertheless produces a warning.  */
 #ifndef _GL_ATTRIBUTE_MAYBE_UNUSED
-# ifdef __has_c_attribute
+# if defined __clang__ && defined __cplusplus
+#  if __clang_major__ >= 10
+#   define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
+#  endif
+# elif defined __has_c_attribute
 #  if __has_c_attribute (__maybe_unused__)
 #   define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
 #  endif