The placement of [[...]] attributes is tricky for compilers that also support
the __attribute__((...)) syntax. See
<https://lists.gnu.org/archive/html/bug-gnulib/2023-04/msg00116.html>.

In the current state, is is quite possible that when a new version of gcc
or clang gets released, with support for [[reproducible]] and [[unsequenced]],
that this causes syntax errors (either in C mode or in C++ mode) in packages
that have already been released.

This would not be good for Gnulib's reputation.

It is better if, for the moment, until we have been able to test such
versions of gcc or clang, we don't use [[reproducible]] and [[unsequenced]]
for such compilers. It will not lead to optimal code generation with new
compiler versions, but that is less important than avoiding compilation errors.

Also, it is quite possible that gcc or clang will make these attributes
available through the __attribute__((...)) syntax, _without_ placement
constraints.

I'm therefore committing this. To be revisited when such gcc and clang
compiler versions have been released.


2024-05-30  Bruno Haible  <br...@clisp.org>

        attribute: Try harder to avoid syntax errors.
        * m4/gnulib-common.m4 (gl_COMMON_BODY): Define
        _GL_ATTRIBUTE_REPRODUCIBLE and _GL_ATTRIBUTE_UNSEQUENCED to empty if
        _GL_BRACKET_BEFORE_ATTRIBUTE is defined.

diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index fba5158ced..b34b4534bf 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -1,5 +1,5 @@
 # gnulib-common.m4
-# serial 94
+# serial 95
 dnl Copyright (C) 2007-2024 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -556,9 +556,14 @@ AC_DEFUN([gl_COMMON_BODY]
    <https://stackoverflow.com/questions/76847905/>.  */
 /* Applies to: functions, pointer to functions, function types.  */
 #ifndef _GL_ATTRIBUTE_REPRODUCIBLE
-# if _GL_HAS_ATTRIBUTE (reproducible)
-#  define _GL_ATTRIBUTE_REPRODUCIBLE [[reproducible]]
-# else
+/* This may be revisited when gcc and clang support [[reproducible]] or 
possibly
+   __attribute__ ((__reproducible__)).  */
+# ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
+#  if _GL_HAS_ATTRIBUTE (reproducible)
+#   define _GL_ATTRIBUTE_REPRODUCIBLE [[reproducible]]
+#  endif
+# endif
+# ifndef _GL_ATTRIBUTE_REPRODUCIBLE
 #  define _GL_ATTRIBUTE_REPRODUCIBLE
 # endif
 #endif
@@ -602,9 +607,14 @@ AC_DEFUN([gl_COMMON_BODY]
    <https://stackoverflow.com/questions/76847905/>.  */
 /* Applies to: functions, pointer to functions, function types.  */
 #ifndef _GL_ATTRIBUTE_UNSEQUENCED
-# if _GL_HAS_ATTRIBUTE (unsequenced)
-#  define _GL_ATTRIBUTE_UNSEQUENCED [[unsequenced]]
-# else
+/* This may be revisited when gcc and clang support [[unsequenced]] or possibly
+   __attribute__ ((__unsequenced__)).  */
+# ifndef _GL_BRACKET_BEFORE_ATTRIBUTE
+#  if _GL_HAS_ATTRIBUTE (unsequenced)
+#   define _GL_ATTRIBUTE_UNSEQUENCED [[unsequenced]]
+#  endif
+# endif
+# ifndef _GL_ATTRIBUTE_UNSEQUENCED
 #  define _GL_ATTRIBUTE_UNSEQUENCED
 # endif
 #endif




Reply via email to