From: Paul Eggert <eggert@cs.ucla.edu>
To: Bruno Haible <bruno@clisp.org>
Cc: bug-gnulib@gnu.org
Subject: Re: Avoid clang warnings regarding [[__nodiscard__]]
Date: Sat, 28 Jan 2023 11:06:05 -0800 [thread overview]
Message-ID: <0994b74a-97da-1650-3c21-00089936c24e@cs.ucla.edu> (raw)
In-Reply-To: <4082365.HAeao5ULc5@nimes>
[-- Attachment #1: Type: text/plain, Size: 387 bytes --]
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?
[-- Attachment #2: nodiscard.diff --]
[-- Type: text/x-patch, Size: 876 bytes --]
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
next prev parent reply other threads:[~2023-01-28 19:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-28 10:57 Avoid clang warnings regarding [[__nodiscard__]] Bruno Haible
2023-01-28 19:06 ` Paul Eggert [this message]
2023-01-28 19:22 ` Bruno Haible
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0994b74a-97da-1650-3c21-00089936c24e@cs.ucla.edu \
--to=eggert@cs.ucla.edu \
--cc=bruno@clisp.org \
--cc=bug-gnulib@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).