CURRENT: CLANG 3.3 and -stad=c++11 and -stdlib=libc++: isnan()/isninf() oddity

Pasi Parviainen pasi.parviainen at
Mon Jul 29 15:42:50 UTC 2013

On 29.7.2013 14:27, Raphael Kubo da Costa wrote:
> David Chisnall <theraven at> writes:
>> On 28 Jul 2013, at 22:27, Raphael Kubo da Costa <rakuco at> wrote:
>>> This seems to have been committed in r253321, and broke some code that
>>> was working with r253320; namely, some code in x11/kde4-workspace
>>> includes math.h and calls isnan() with a const double.
>> Please provide a test case.  Specifically, I need to know what
>> language dialect this is using, because I have tested including math.h
>> and calling isnan(double) with c89, gnu89, c99, c11, c++03 and c++11
>> on gcc (for the modes that it supports) and clang.
> I get the following results with and without -std=c++11 and/or
> -stdlib=libc++:
> % cat
> #include <math.h>
> int main() {
>    const double d = 42.0;
>    return isnan(d) ? 1 : 0;
> }
> % clang++
> error: controlling expression type 'const double' not
> compatible with any generic association type
>    return isnan(d) ? 1 : 0;
>           ^~~~~~~~
> /usr/include/math.h:109:2: note: expanded from macro 'isnan'
>          __fp_type_select(x, __inline_isnanf, __inline_isnan,
>          __inline_isnanl)
>          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> /usr/include/math.h:86:49: note: expanded from macro '__fp_type_select'
> #define __fp_type_select(x, f, d, ld) _Generic((0,(x)),
> \
>                                                  ^~~~~
> 1 error generated.

In the first place C++ code should be using cmath instead of math.h. 
That said, this is a result of just an another wonderful little 
difference between C and C++. C standard explicitly states that comma 
operator does not yield an lvalue but in C++ it can if the right most 
operand is an lvalue. If C++ compatibility is desired then unary + 
operator (e.g. _Generic(+(x),...) could be used for the same effect, 
only downside with this is that the integer arguments are promoted, but 
that doesn't matter in this case.


More information about the freebsd-standards mailing list