[PATCH] assert.h: allow gcc to detect assert(a = 1) errors
Zack Weinberg
zackw@panix.com
Thu Nov 24 02:59:00 GMT 2016
On Wed, Nov 23, 2016 at 9:21 PM, Jim Meyering <jim@meyering.net> wrote:
[...]
Not commenting on anything else, but...
> We *do* need that __STRICT_ANSI__ disjunct.
> Otherwise, this would evoke no warning:
>
> $ gcc -isystem. -I. -Werror=pedantic k.c
> In file included from k.c:1:0:
> k.c: In function ‘main’:
> k.c:2:23: warning: ISO C forbids braced-groups within expressions [-Wpedantic]
> int main() { assert ( ({1;}) ); return 0; }
... Would you please file a feature-request with the gcc people asking
for something that turns __extension__ back off? It would be nice to
be able to get this right even in __STRICT_ANSI__ mode. I'm imagining
that your macro could look like
#define assert(expr) \
__extension__ ({ \
if (__noextension__ (expr)) \
; \
else
__assert_failed (...); \
(void)0; \
})
(Make clear that the parentheses in __noextension__(...) need to not
count for the purpose of -Wparentheses.)
zw
More information about the Libc-alpha
mailing list