On 2023-01-28 02:57, Bruno Haible wrote:
+ /* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]]
produces
+ a warning. */
+# if __clang_major__ >= 1000
I found this a little hard to follow, as I don't know __clang_major__ by
heart and at first misread that as version 10.0.0. How about something
like the attached, to simplify this for Clang non-experts?
diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4
index d632819864..bb5a2029af 100644
--- a/m4/gnulib-common.m4
+++ b/m4/gnulib-common.m4
@@ -379,14 +379,11 @@ AC_DEFUN([gl_COMMON_BODY], [
the return value, unless the caller uses something like ignore_value. */
/* Applies to: function, enumeration, class. */
#ifndef _GL_ATTRIBUTE_NODISCARD
-# if defined __clang__ && defined __cplusplus
/* With clang up to 15.0.6 (at least), in C++ mode, [[__nodiscard__]] produces
a warning. */
-# if __clang_major__ >= 1000
-# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
-# endif
-# elif defined __has_c_attribute
-# if __has_c_attribute (__nodiscard__)
+# ifdef __has_c_attribute
+# if (__has_c_attribute (__nodiscard__) \
+ && ! (defined __clang__ && defined __cplusplus))
# define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
# endif
# endif