Re: CURRENT: CLANG 3.3 and -stad=c++11 and -stdlib=libc++:

看板FB_current作者時間12年前 (2013/07/30 02:01), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串25/26 (看更多)
On 29.7.2013 14:27, Raphael Kubo da Costa wrote: > David Chisnall <theraven@FreeBSD.org> writes: > >> On 28 Jul 2013, at 22:27, Raphael Kubo da Costa <rakuco@freebsd.org> 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 isnan.cc > #include <math.h> > int main() { > const double d = 42.0; > return isnan(d) ? 1 : 0; > } > > % clang++ isnan.cc > isnan.cc:4:10: 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. Pasi _______________________________________________ freebsd-current@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-current To unsubscribe, send any mail to "freebsd-current-unsubscribe@freebsd.org"
文章代碼(AID): #1HzgtWH7 (FB_current)
討論串 (同標題文章)
完整討論串 (本文為第 25 之 26 篇):
文章代碼(AID): #1HzgtWH7 (FB_current)