]> 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:57:19 +0000 (03:57 +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 9689c438b825f50964525054be91874f7edb25ae..b9ca4abe35fd39f62513cfb044e3c2b7eb58f68b 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 c820d294876288b25140996a1dfb2864fc2776d3..05f7e3937ff16700429e009889e7343acc67fba7 100644 (file)
@@ -1,4 +1,4 @@
-# gnulib-common.m4 serial 73.3
+# gnulib-common.m4 serial 73.4
 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,
@@ -372,7 +372,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
-# if _GL_HAS_C_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 _GL_HAS_C_ATTRIBUTE (nodiscard)
 #  define _GL_ATTRIBUTE_NODISCARD [[__nodiscard__]]
 # elif _GL_HAS_ATTRIBUTE (warn_unused_result)
 #  define _GL_ATTRIBUTE_NODISCARD __attribute__ ((__warn_unused_result__))