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: Florian Weimer <fweimer at redhat 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, 14 Dec 2016 10:13:41 +0100
- 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> <93a7b09e-70b9-d11e-bfb5-e54e751c8db5@redhat.com> <CA+8g5KGiN54O-jV7-NEP-4a9FrP6tio0xp2J=V0x-QX4tfAz2A@mail.gmail.com>
On 11/26/2016 07:14 AM, Jim Meyering wrote:
Here's a proposed ChangeLog entry:
2016-11-25 Jim Meyering <meyering@fb.com>
Let gcc detect assert(a = 1) errors.
* assert/assert.h (assert): Rewrite assert's definition so that a
s/==/=/ typo, e.g., assert(errno = ENOENT) is not hidden from
gcc's -Wparentheses by assert-added parentheses. The new
definition uses "if (expr) /* empty */; else __assert_fail...",
so gcc -Wall will now detect that type of error in an assert, too.
The __STRICT_ANSI__ disjunct is to avoid the warning that -Wpedantic
would otherwise issue for the use of ({...}).
Isn't this warning suppressed for system headers with -Wpedantic?
I would have preferred
to use __extension__ to mark that, but doing so would mistakenly
suppress warnings about any extension in the user-supplied "expr".
E.g., "assert ( ({1;}) )" must continue to evoke a warning.
https://bugzilla.redhat.com/1105335
The following is a bit silly. glibc adheres to the GNU standards, which
require that the ChangeLog only describes the change as such, not its
rationale. So the entry should probably look like this.
Let GCC detect assert (a = 1) errors.
* assert/assert.h (assert): Introduce __STRICT_ANSI__ variant.
Use a GCC extension and an if statement for GNU compilers.
Thanks,
Florian