From 8ca04dc0ceb71ff5b863c7f656898ab339aeb406 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 417820715d..6b993b52df 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 cf0fc5a1e7..d632819864 100644 --- a/m4/gnulib-common.m4 +++ b/m4/gnulib-common.m4 @@ -1,4 +1,4 @@ -# gnulib-common.m4 serial 79 +# gnulib-common.m4 serial 80 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 -- 2.39.5