]> Savannah Git Hosting - gnulib.git/commitdiff
Avoid clang warnings regarding [[__nodiscard__]].
authorBruno Haible <bruno@clisp.org>
Sat, 28 Jan 2023 10:52:40 +0000 (11:52 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 10 Feb 2023 02:19:59 +0000 (03:19 +0100)
* m4/gnulib-common.m4 (gl_COMMON_BODY): For clang, in C++ mode, ignore
the __has_c_attribute value and define _GL_ATTRIBUTE_NODISCARD to
__attribute__ ((__warn_unused_result__)), not [[__nodiscard__]].

ChangeLog
m4/gnulib-common.m4

index 088a18bdad8edf4e81ac2561c4293bc0317addf8..a892621b40f2f4c8a9d391d2918215a963336be3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2023-01-28  Bruno Haible  <bruno@clisp.org>
+
+       Avoid clang warnings regarding [[__nodiscard__]].
+       * m4/gnulib-common.m4 (gl_COMMON_BODY): For clang, in C++ mode, ignore
+       the __has_c_attribute value and define _GL_ATTRIBUTE_NODISCARD to
+       __attribute__ ((__warn_unused_result__)), not [[__nodiscard__]].
+
 2023-01-28  Bruno Haible  <bruno@clisp.org>
 
        Avoid clang warnings regarding [[__maybe_unused__]].
index 893465c02ee7899653aff1e870ef1ba2fc06b3d5..808efc4ab12019b3f5bcd9b1f0b6457bc53513e0 100644 (file)
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 75b
+# gnulib-common.m4 serial 75c
 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,
@@ -379,7 +379,13 @@ 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
-# ifdef __has_c_attribute
+# 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__)
 #   define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
 #  endif