Bug#123468: [Bug c/6906] warn about asserts with side effects
- To: 123468@bugs.debian.org
- Subject: Bug#123468: [Bug c/6906] warn about asserts with side effects
- From: "felix.von.s at posteo dot de" <gcc-bugzilla@gcc.gnu.org>
- Date: Thu, 16 Apr 2020 17:43:09 +0000
- Message-id: <bug-6906-1490-yYqRNMMpFy@http.gcc.gnu.org/bugzilla/>
- Reply-to: "felix.von.s at posteo dot de" <gcc-bugzilla@gcc.gnu.org>, 123468@bugs.debian.org
- In-reply-to: <bug-6906-1490@http.gcc.gnu.org/bugzilla/>
- References: <bug-6906-1490@http.gcc.gnu.org/bugzilla/> <E16DsBH-0002ZX-00@localhost>
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.
--
You are receiving this mail because:
You reported the bug.
Reply to: