This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] assert: Suppress pedantic warning caused by statement expression [BZ# 21242]


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]