public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "felix.von.s at posteo dot de" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/6906] warn about asserts with side effects
Date: Thu, 16 Apr 2020 17:43:09 +0000 [thread overview]
Message-ID: <bug-6906-4-ejCv5krABp@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-6906-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=6906
felix <felix.von.s at posteo dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |felix.von.s at posteo dot de
--- Comment #9 from felix <felix.von.s at posteo dot de> ---
I have just realised that __builtin_pure_p is already expressible:
#define __builtin_pure_p(expr) \
(__builtin_object_size(((void)(expr), ""), 2))
If (expr) is free of side effects, this is the same as
__builtin_object_size("", 2), which is 1. Otherwise, the expression returns 0.
This is documented behaviour, by the way. The documentation for
__builtin_object_size at
<https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html> states:
> __builtin_object_size never evaluates its arguments for side effects.
> If there are any side effects in them, it returns (size_t) -1 for
> type 0 or 1 and (size_t) 0 for type 2 or 3.
Experimentation reveals __attribute__((pure)) is enough for
__builtin_object_size to consider a function free of side effects.
next parent reply other threads:[~2020-04-16 17:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <bug-6906-4@http.gcc.gnu.org/bugzilla/>
2020-04-16 17:43 ` felix.von.s at posteo dot de [this message]
[not found] <bug-6906-1490@http.gcc.gnu.org/bugzilla/>
2006-10-15 19:45 ` pinskia at gcc dot gnu dot org
2008-03-03 2:56 ` chris dot pickett at mail dot mcgill dot ca
[not found] <20020601163600.6906.123468@bugs.debian.org>
2003-12-31 17:20 ` pinskia at gcc dot gnu dot org
2004-08-10 23:56 ` mbp at sourcefrog dot net
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bug-6906-4-ejCv5krABp@http.gcc.gnu.org/bugzilla/ \
--to=gcc-bugzilla@gcc.gnu.org \
--cc=gcc-bugs@gcc.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).