This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] assert.h: allow gcc to detect assert(a = 1) errors
- From: Zack Weinberg <zackw at panix dot com>
- To: Jim Meyering <jim at meyering dot net>
- Cc: Roland McGrath <roland at hack dot frob dot com>, libc-alpha <libc-alpha at sourceware dot org>
- Date: Wed, 23 Nov 2016 21:59:25 -0500
- Subject: Re: [PATCH] assert.h: allow gcc to detect assert(a = 1) errors
- Authentication-results: sourceware.org; auth=none
- References: <1405537923-28692-1-git-send-email-jim@meyering.net> <20140716201505.34FF22C398F@topped-with-meat.com> <CA+8g5KH_vG9KY-fT8miGH9oSULCoffd5DQQbgr-GDR6d2qTktA@mail.gmail.com> <CA+8g5KFy4tk+H3t0BKoe=wQqsW+ea3ZtzOe2bb+xBUNbtxGBWg@mail.gmail.com>
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