From 5ac16181d387546110117c70cc82e721e3198723 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 28 Jan 2023 11:52:40 +0100 Subject: [PATCH] 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__]]. --- ChangeLog | 7 +++++++ m4/gnulib-common.m4 | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9689c438b8..b9ca4abe35 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2023-01-28 Bruno Haible + + 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 Avoid clang warnings regarding [[__maybe_unused__]]. diff --git a/m4/gnulib-common.m4 b/m4/gnulib-common.m4 index c820d29487..05f7e3937f 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -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__)) -- 2.39.5