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: Support types without operator== (int) [BZ #21972]


On 08/18/2017 09:17 PM, Paul Eggert wrote:
> Florian Weimer wrote:
>> I think it's still valuable to use static_cast<bool> (expr) for C++
>> because we don't need any extensions (except __FUNCTION__ for early C++)
>> because the parentheses do not count in this context; assert (a = 1)
>> still results in a warning.
> 
> OK, but in that case the C version shouldn't use 'sizeof ((expr) ? 1 :
> 0)' either, right? As that would suppress the warning in the C case.

We are interested in two warnings:

  assert (a = 1);
  assert (({ 1; }));

The first one is about the assignment (and should happen in as many
cases as possible), and the second one is about pedantic warnings in
strict standard mode.

For GNU C, we need to use __extension__ ({ if (E) …  }) to evaluate the
expression without extra parentheses in a Boolean context to get the
first warning, but the __extension__ inhibits the warning for the second
construct, so we expand it twice.  The expansion in the sizeof will not
warn about the assignment, but that's fine because we catch that with
the other expansion.

> So
> it sounds like your original patch was right after all (and sorry about
> the noise...).

I think the last patch is superior because we get the first warning even
in strict C++ mode.

I'll delete a couple more operators before committing it.

Thanks,
Florian


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