[PATCH] assert: Support types without operator== (int) [BZ #21972]

Florian Weimer fw@deneb.enyo.de
Fri Aug 18 16:59:00 GMT 2017


* Paul Eggert:

> Florian Weimer wrote:
>> + ((void) sizeof (static_cast<bool> (expr)), __extension__ ({ \
>
> Can we instead replace 'sizeof ((expr) == 0)' with 'sizeof !(expr)'?
> That works in C, and if it also works in C++ it would avoid the need
> for the #ifdef __cplusplus.

It does not work in C++ because operator! could have been overloaded
or deleted.  It is likely that a future C++ standard will only require
that the expression can be contextually converted to bool, and this is
what the static_cast approach relies upon.



More information about the Libc-alpha mailing list