]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-common: don’t suppress -Wpedantic
authorPaul Eggert <eggert@cs.ucla.edu>
Thu, 21 Sep 2023 21:26:24 +0000 (14:26 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Thu, 21 Sep 2023 21:26:24 +0000 (14:26 -0700)
Problem reported by Pádraig Brady in:
https://lists.gnu.org/r/bug-gnulib/2023-09/msg00130.html
* m4/gnulib-common.m4 (_GL_HAVE___HAS_C_ATTRIBUTE): New macro.
Use it instead of ‘defined __has_c_attribute’.

ChangeLog
m4/gnulib-common.m4

index 65315fc973327896ac75b842ba9e315e416fdd3d..160332c1160c72f623a546c87ca3737226c5d0a3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2023-09-21  Paul Eggert  <eggert@cs.ucla.edu>
 
+       gnulib-common: don’t suppress -Wpedantic
+       Problem reported by Pádraig Brady in:
+       https://lists.gnu.org/r/bug-gnulib/2023-09/msg00130.html
+       * m4/gnulib-common.m4 (_GL_HAVE___HAS_C_ATTRIBUTE): New macro.
+       Use it instead of ‘defined __has_c_attribute’.
+
        crypto/sm3: rename gl_cv_* variable for clarity
        * m4/gc-sm3.m4 (gl_cv_libgcrypt_md_sm3):
        Rename from gl_cv_libcrypt_md_sm3 since this is unrelated to libcrypt.
index c3723161356c0d42a9e5b03676dad8a58058a8d3..b3852a595ee6fa485798445df627ad414ecc91f1 100644 (file)
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 88
+# gnulib-common.m4 serial 89
 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,
@@ -114,10 +114,14 @@ AC_DEFUN([gl_COMMON_BODY], [
 # define _GL_ATTR_warn_unused_result _GL_GNUC_PREREQ (3, 4)
 #endif
 
-/* Disable GCC -Wpedantic if using __has_c_attribute and this is not C23+.  */
-#if (defined __has_c_attribute && _GL_GNUC_PREREQ (4, 6) \
-     && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710)
-# pragma GCC diagnostic ignored "-Wpedantic"
+/* Use __has_c_attribute if available.  However, do not use with
+   pre-C23 GCC, which can issue false positives if -Wpedantic.  */
+#if (defined __has_c_attribute \
+     && ! (_GL_GNUC_PREREQ (4, 6) \
+           && (defined __STDC_VERSION__ ? __STDC_VERSION__ : 0) <= 201710))
+# define _GL_HAVE___HAS_C_ATTRIBUTE 1
+#else
+# define _GL_HAVE___HAS_C_ATTRIBUTE 0
 #endif
 
 /* Define if, in a function declaration, the attributes in bracket syntax
@@ -242,7 +246,7 @@ AC_DEFUN([gl_COMMON_BODY], [
    in C++ also: namespace, class, template specialization.  */
 #ifndef _GL_ATTRIBUTE_DEPRECATED
 # ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
-#  ifdef __has_c_attribute
+#  if _GL_HAVE___HAS_C_ATTRIBUTE
 #   if __has_c_attribute (__deprecated__)
 #    define _GL_ATTRIBUTE_DEPRECATED [[__deprecated__]]
 #   endif
@@ -291,7 +295,7 @@ AC_DEFUN([gl_COMMON_BODY], [
 /* Applies to: Empty statement (;), inside a 'switch' statement.  */
 /* Always expands to something.  */
 #ifndef _GL_ATTRIBUTE_FALLTHROUGH
-# ifdef __has_c_attribute
+# if _GL_HAVE___HAS_C_ATTRIBUTE
 #  if __has_c_attribute (__fallthrough__)
 #   define _GL_ATTRIBUTE_FALLTHROUGH [[__fallthrough__]]
 #  endif
@@ -380,7 +384,7 @@ AC_DEFUN([gl_COMMON_BODY], [
 #   if !defined __apple_build_version__ && __clang_major__ >= 10
 #    define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
 #   endif
-#  elif defined __has_c_attribute
+#  elif _GL_HAVE___HAS_C_ATTRIBUTE
 #   if __has_c_attribute (__maybe_unused__)
 #    define _GL_ATTRIBUTE_MAYBE_UNUSED [[__maybe_unused__]]
 #   endif
@@ -411,7 +415,7 @@ AC_DEFUN([gl_COMMON_BODY], [
 #   if __clang_major__ >= 1000
 #    define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
 #   endif
-#  elif defined __has_c_attribute
+#  elif _GL_HAVE___HAS_C_ATTRIBUTE
 #   if __has_c_attribute (__nodiscard__)
 #    define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
 #   endif