Commit f235ad11 by Jason Merrill Committed by Jason Merrill

Core DR 1288

	Core DR 1288
	* call.c (reference_binding): Only elide braces if the single
	element is reference-related.

From-SVN: r207164
parent 30f6b784
2014-01-27 Jason Merrill <jason@redhat.com> 2014-01-27 Jason Merrill <jason@redhat.com>
Core DR 1288
* call.c (reference_binding): Only elide braces if the single
element is reference-related.
PR c++/58814 PR c++/58814
* typeck.c (cp_build_modify_expr): Make the RHS an rvalue before * typeck.c (cp_build_modify_expr): Make the RHS an rvalue before
stabilizing. stabilizing.
......
...@@ -1460,16 +1460,29 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags, ...@@ -1460,16 +1460,29 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr)) if (expr && BRACE_ENCLOSED_INITIALIZER_P (expr))
{ {
maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS); maybe_warn_cpp0x (CPP0X_INITIALIZER_LISTS);
conv = implicit_conversion (to, from, expr, c_cast_p, /* DR 1288: Otherwise, if the initializer list has a single element
flags, complain); of type E and ... [T's] referenced type is reference-related to E,
if (!CLASS_TYPE_P (to) the object or reference is initialized from that element... */
&& CONSTRUCTOR_NELTS (expr) == 1) if (CONSTRUCTOR_NELTS (expr) == 1)
{ {
expr = CONSTRUCTOR_ELT (expr, 0)->value; tree elt = CONSTRUCTOR_ELT (expr, 0)->value;
if (error_operand_p (expr)) if (error_operand_p (elt))
return NULL; return NULL;
from = TREE_TYPE (expr); tree etype = TREE_TYPE (elt);
if (reference_related_p (to, etype))
{
expr = elt;
from = etype;
goto skip;
}
} }
/* Otherwise, if T is a reference type, a prvalue temporary of the
type referenced by T is copy-list-initialized or
direct-list-initialized, depending on the kind of initialization
for the reference, and the reference is bound to that temporary. */
conv = implicit_conversion (to, from, expr, c_cast_p,
flags, complain);
skip:;
} }
if (TREE_CODE (from) == REFERENCE_TYPE) if (TREE_CODE (from) == REFERENCE_TYPE)
......
// Core issue 934 // Core issue 934/1288
// { dg-options "-std=c++11" } // { dg-options "-std=c++11" }
int i; int i;
...@@ -13,12 +13,12 @@ struct A { int i; } a; ...@@ -13,12 +13,12 @@ struct A { int i; } a;
A& r5 { i }; // { dg-error "" } reference to temporary A& r5 { i }; // { dg-error "" } reference to temporary
A&& r6 { i }; // OK, aggregate initialization of temporary A&& r6 { i }; // OK, aggregate initialization of temporary
A& r7 { a }; // { dg-error "" } invalid aggregate initializer for A A& r7 { a }; // OK, direct-initialization
A&& r8 { a }; // { dg-error "" } invalid aggregate initializer for A A&& r8 { a }; // { dg-error "lvalue" } binding && to lvalue
struct B { B(int); int i; } b(0); struct B { B(int); int i; } b(0);
B& r9 { i }; // { dg-error "" } reference to temporary B& r9 { i }; // { dg-error "" } reference to temporary
B&& r10 { i }; // OK, make temporary with B(int) constructor B&& r10 { i }; // OK, make temporary with B(int) constructor
B& r11 { b }; // { dg-error "" } reference to temporary B& r11 { b }; // OK, direct-initialization
B&& r12 { b }; // OK, make temporary with copy constructor B&& r12 { b }; // { dg-error "lvalue" } binding && to lvalue
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