Document 'A name for the null pointer: nullptr (revision 4)' states that implicit conversion of nullptr to bool is not allowed. Unfortunately in g++ 4.7.0, this requirement is not fulfilled. See example below. if (nullptr) //shall return error, implicit conversion to bool not allowed
That document is not the standard, [conv.bool] says "A prvalue of type std::nullptr_t can be converted to a prvalue of type bool; the resulting value is false."
but N.B. http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1423
that DR has been discussed by the committee today and it seems the rule will be changed, so suspending
DR 1423 has now reached ready status, http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1423 so this seems like a good reason to consider a compiler change to evaluate potential code breakages. Here some recommended test-cases that should hold: 1) bool b1 = nullptr; // Is well-formed today, needs to be ill-formed 2) bool b2(nullptr); // well-formed today and under 1423 3) template<class T> T&& make(); template<class T> void sink(T); template<class T1, class T2, class = decltype(sink<T2>(make<T1>())) > auto f(int) -> char(&)[1]; template<class, class> auto f(...) -> char(&)[2]; static_assert(sizeof(f<decltype(nullptr), bool>(0)) != 1, "");
Unsuspending then.
Mine.
Author: paolo Date: Tue Jun 3 17:48:36 2014 New Revision: 211195 URL: http://gcc.gnu.org/viewcvs?rev=211195&root=gcc&view=rev Log: gcc/cp 2014-06-03 Paolo Carlini <paolo.carlini@oracle.com> DR 1423 PR c++/52174 * call.c (standard_conversion): Convert nullptr to bool only in case of direct-initialization. (convert_like_real): Provide informative error message. gcc/testsuite 2014-06-03 Paolo Carlini <paolo.carlini@oracle.com> DR 1423 PR c++/52174 * g++.dg/cpp0x/nullptr31.C: New. * g++.dg/cpp0x/sfinae-nullptr1.C: Likewise. * g++.dg/cpp0x/nullptr17.C: Update. libstdc++-v3 2014-06-03 Paolo Carlini <paolo.carlini@oracle.com> DR 1423 PR c++/52174 * testsuite/20_util/is_assignable/value.cc: Update. Added: trunk/gcc/testsuite/g++.dg/cpp0x/nullptr31.C trunk/gcc/testsuite/g++.dg/cpp0x/sfinae-nullptr1.C Modified: trunk/gcc/cp/ChangeLog trunk/gcc/cp/call.c trunk/gcc/testsuite/ChangeLog trunk/gcc/testsuite/g++.dg/cpp0x/nullptr17.C trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/testsuite/20_util/is_assignable/value.cc
Fixed for 4.10.0.