Commit 3c61a5ba by Paolo Carlini Committed by Paolo Carlini

DR 1423 PR c++/52174

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.

From-SVN: r211195
parent fedfecef
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.
2014-06-03 Marek Polacek <polacek@redhat.com> 2014-06-03 Marek Polacek <polacek@redhat.com>
PR c/60439 PR c/60439
......
...@@ -1311,10 +1311,10 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p, ...@@ -1311,10 +1311,10 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
{ {
/* [conv.bool] /* [conv.bool]
An rvalue of arithmetic, unscoped enumeration, pointer, or A prvalue of arithmetic, unscoped enumeration, pointer, or pointer
pointer to member type can be converted to an rvalue of type to member type can be converted to a prvalue of type bool. ...
bool. ... An rvalue of type std::nullptr_t can be converted For direct-initialization (8.5 [dcl.init]), a prvalue of type
to an rvalue of type bool; */ std::nullptr_t can be converted to a prvalue of type bool; */
if (ARITHMETIC_TYPE_P (from) if (ARITHMETIC_TYPE_P (from)
|| UNSCOPED_ENUM_P (from) || UNSCOPED_ENUM_P (from)
|| fcode == POINTER_TYPE || fcode == POINTER_TYPE
...@@ -1328,6 +1328,8 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p, ...@@ -1328,6 +1328,8 @@ standard_conversion (tree to, tree from, tree expr, bool c_cast_p,
&& conv->rank < cr_pbool) && conv->rank < cr_pbool)
|| NULLPTR_TYPE_P (from)) || NULLPTR_TYPE_P (from))
conv->rank = cr_pbool; conv->rank = cr_pbool;
if (NULLPTR_TYPE_P (from) && (flags & LOOKUP_ONLYCONVERTING))
conv->bad_p = true;
return conv; return conv;
} }
...@@ -6062,6 +6064,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, ...@@ -6062,6 +6064,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
expr = CONSTRUCTOR_ELT (expr, 0)->value; expr = CONSTRUCTOR_ELT (expr, 0)->value;
} }
/* Give a helpful error if this is bad because a conversion to bool
from std::nullptr_t requires direct-initialization. */
if (NULLPTR_TYPE_P (TREE_TYPE (expr))
&& TREE_CODE (totype) == BOOLEAN_TYPE)
complained = permerror (loc, "converting to %qT from %qT requires "
"direct-initialization",
totype, TREE_TYPE (expr));
for (; t ; t = next_conversion (t)) for (; t ; t = next_conversion (t))
{ {
if (t->kind == ck_user && t->cand->reason) if (t->kind == ck_user && t->cand->reason)
......
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.
2014-06-03 Marek Polacek <polacek@redhat.com> 2014-06-03 Marek Polacek <polacek@redhat.com>
PR c/60439 PR c/60439
......
// { dg-do compile { target c++11 } } // { dg-do compile { target c++11 } }
// Test that bool is a better overload match than int // Used to test that bool is a better overload match than int
// Updated for DR 1423
template <typename T, typename U> struct tType_equal; template <typename T, typename U> struct tType_equal;
template <typename T> struct tType_equal<T, T> { typedef void type; }; template <typename T> struct tType_equal<T, T> { typedef void type; };
...@@ -16,7 +17,7 @@ bool i( bool ); ...@@ -16,7 +17,7 @@ bool i( bool );
void test_i() void test_i()
{ {
// Overload to bool, not int // Overload to bool, not int
type_equal<bool>(i(nullptr)); type_equal<bool>(i(nullptr)); // { dg-error "direct" }
decltype(nullptr) mynull = 0; decltype(nullptr) mynull = 0;
type_equal<bool>(i(mynull)); type_equal<bool>(i(mynull)); // { dg-error "direct" }
} }
// DR 1423, PR c++/52174
// { dg-do compile { target c++11 } }
bool b1 = nullptr; // { dg-error "direct" }
bool b2(nullptr);
bool b3{nullptr};
int i1 = nullptr; // { dg-error "cannot convert" }
int i2(nullptr); // { dg-error "cannot convert" }
int i3{nullptr}; // { dg-error "cannot convert" }
// DR 1423, PR c++/52174
// { dg-do compile { target c++11 } }
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, "");
2014-06-03 Paolo Carlini <paolo.carlini@oracle.com>
DR 1423
PR c++/52174
* testsuite/20_util/is_assignable/value.cc: Update.
2014-06-02 Jonathan Wakely <jwakely@redhat.com> 2014-06-02 Jonathan Wakely <jwakely@redhat.com>
* include/std/condition_variable (condition_variable_any::_Unlock): Do * include/std/condition_variable (condition_variable_any::_Unlock): Do
......
...@@ -174,7 +174,7 @@ static_assert(!std::is_assignable<bool&, SE>::value, "Error"); ...@@ -174,7 +174,7 @@ static_assert(!std::is_assignable<bool&, SE>::value, "Error");
static_assert(std::is_assignable<bool&, void*>::value, "Error"); static_assert(std::is_assignable<bool&, void*>::value, "Error");
static_assert(std::is_assignable<bool&, int B::*>::value, "Error"); static_assert(std::is_assignable<bool&, int B::*>::value, "Error");
static_assert(std::is_assignable<bool&, void*>::value, "Error"); static_assert(std::is_assignable<bool&, void*>::value, "Error");
static_assert(std::is_assignable<bool&, std::nullptr_t>::value, "Error"); static_assert(!std::is_assignable<bool&, std::nullptr_t>::value, "Error");
static_assert(std::is_assignable<std::nullptr_t&, static_assert(std::is_assignable<std::nullptr_t&,
std::nullptr_t>::value, "Error"); std::nullptr_t>::value, "Error");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment