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: Florian Weimer <fweimer at redhat dot com>
- To: Zack Weinberg <zackw at panix dot com>
- Cc: GNU C Library <libc-alpha at sourceware dot org>
- Date: Wed, 5 Jul 2017 17:51:14 +0200
- Subject: Re: [PATCH] assert: Suppress pedantic warning caused by statement expression [BZ# 21242]
- Authentication-results: sourceware.org; auth=none
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com
- Authentication-results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=pass smtp.mailfrom=fweimer at redhat dot com
- Dkim-filter: OpenDKIM Filter v2.11.0 mx1.redhat.com CF271C04B954
- Dmarc-filter: OpenDMARC Filter v1.3.2 mx1.redhat.com CF271C04B954
- 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> <CAKCAbMjD4rkFo6CL4WGbL9T0ZUenBY_7KCUb_MRYGAEyPejWLQ@mail.gmail.com>
On 07/05/2017 05:46 PM, Zack Weinberg wrote:
> 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.
The type of the sizeof argument would still be int (due to the
comparison against 0), so this doesn't actually occur.
Florian