This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH] assert: Suppress pedantic warning caused by statement expression [BZ# 21242]
- From: Zack Weinberg <zackw at panix dot com>
- To: Florian Weimer <fweimer at redhat dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Wed, 5 Jul 2017 11:46:41 -0400
- Subject: Re: [PATCH] assert: Suppress pedantic warning caused by statement expression [BZ# 21242]
- Authentication-results: sourceware.org; auth=none
- References: <6619e7e2-248e-08bc-6dc5-7b4d11bea3df@auburn.edu> <925e8a81-86f9-78a6-1578-660c04e39e3c@redhat.com> <alpine.DEB.2.20.1703211617300.8480@digraph.polyomino.org.uk> <b3e54310-9e08-c0fb-b0ee-b2a07711ef9a@redhat.com> <alpine.DEB.2.20.1706261055440.21187@digraph.polyomino.org.uk> <b50d764b-0616-855d-8359-a34d1210acfd@redhat.com> <a26386c3-7c12-be12-14f4-4d3ca7930452@redhat.com>
On Tue, Jul 4, 2017 at 10:10 AM, Florian Weimer <fweimer@redhat.com> wrote:
> On 07/04/2017 04:00 PM, Florian Weimer wrote:
>> On 06/26/2017 12:56 PM, Joseph Myers wrote:
>>> On Sun, 25 Jun 2017, Florian Weimer wrote:
>>>
>>>> I think we can use __extension__ if we also expand the expression
>>>> without __extension__ in an unevaluated context.
...
>>
>> This is what I came up with as a patch.
>>
>> I would consider this still appropriate during the freeze. It's
>> something we'd backport to glibc 2.25, too.
>
> Hopefully now with attachment.
...
> +/* The first occurrence of EXPR is not evaluated due to the sizeof,
> + but will trigger any pedantic warnings masked by the __extension__
> + for the second occurrence. The explicit comparison against zero is
> + required to support function pointers and bit fields in this
> + context. */
> # define assert(expr) \
> - ({ \
> + ((void) sizeof ((expr) == 0), __extension__ ({ \
A problem occurs to me: expressions involving VLAs _are_ evaluated
inside sizeof. Consider
extern int f(int);
void g(void)
{
const int n = 4;
int array[n] = { 0, 0, 0, 0 }; // in C99, array is a VLA
assert(array[f(n)] == 0);
}
f() should be called only once, but I _think_ it will be called twice
with this definition of assert.
zw