Commit 5794b9f6 by Jason Merrill Committed by Jason Merrill

PR c++/54293 - binding reference to member of temporary

	* call.c (reference_binding): Fix binding to member of temporary.

From-SVN: r240819
parent 27afd940
2016-10-05 Jason Merrill <jason@redhat.com> 2016-10-05 Jason Merrill <jason@redhat.com>
PR c++/54293
* call.c (reference_binding): Fix binding to member of temporary.
* call.c (extend_ref_init_temps): Fix TARGET_EXPR handling. * call.c (extend_ref_init_temps): Fix TARGET_EXPR handling.
* parser.c (cp_parser_skip_to_end_of_statement): Add missing break. * parser.c (cp_parser_skip_to_end_of_statement): Add missing break.
......
...@@ -1539,15 +1539,20 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags, ...@@ -1539,15 +1539,20 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
gl_kind = clk_rvalueref; gl_kind = clk_rvalueref;
} }
else if (expr) else if (expr)
{ gl_kind = lvalue_kind (expr);
gl_kind = lvalue_kind (expr); else if (CLASS_TYPE_P (from)
if (gl_kind & clk_class) || TREE_CODE (from) == ARRAY_TYPE)
/* A class prvalue is not a glvalue. */ gl_kind = clk_class;
gl_kind = clk_none;
}
else else
gl_kind = clk_none; gl_kind = clk_none;
is_lvalue = gl_kind && !(gl_kind & clk_rvalueref);
/* Don't allow a class prvalue when LOOKUP_NO_TEMP_BIND. */
if ((flags & LOOKUP_NO_TEMP_BIND)
&& (gl_kind & clk_class))
gl_kind = clk_none;
/* Same mask as real_lvalue_p. */
is_lvalue = gl_kind && !(gl_kind & (clk_rvalueref|clk_class));
tfrom = from; tfrom = from;
if ((gl_kind & clk_bitfield) != 0) if ((gl_kind & clk_bitfield) != 0)
...@@ -1569,11 +1574,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags, ...@@ -1569,11 +1574,7 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
[8.5.3/5 dcl.init.ref] is changed to also require direct bindings for [8.5.3/5 dcl.init.ref] is changed to also require direct bindings for
const and rvalue references to rvalues of compatible class type. const and rvalue references to rvalues of compatible class type.
We should also do direct bindings for non-class xvalues. */ We should also do direct bindings for non-class xvalues. */
if (related_p if (related_p && gl_kind)
&& (gl_kind
|| (!(flags & LOOKUP_NO_TEMP_BIND)
&& (CLASS_TYPE_P (from)
|| TREE_CODE (from) == ARRAY_TYPE))))
{ {
/* [dcl.init.ref] /* [dcl.init.ref]
......
...@@ -11,7 +11,11 @@ struct A ...@@ -11,7 +11,11 @@ struct A
int main() int main()
{ {
const int &r = A().i; {
const int &r = A().i;
if (d != 0)
return 1;
}
if (d != 1) if (d != 1)
return 1; return 1;
} }
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