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

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

From-SVN: r240819
This commit is contained in:
Jason Merrill 2016-10-05 18:58:55 -04:00 committed by Jason Merrill
parent 27afd940ce
commit 5794b9f622
3 changed files with 21 additions and 13 deletions

View File

@ -1,5 +1,8 @@
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.
* parser.c (cp_parser_skip_to_end_of_statement): Add missing break.

View File

@ -1539,15 +1539,20 @@ reference_binding (tree rto, tree rfrom, tree expr, bool c_cast_p, int flags,
gl_kind = clk_rvalueref;
}
else if (expr)
{
gl_kind = lvalue_kind (expr);
if (gl_kind & clk_class)
/* A class prvalue is not a glvalue. */
gl_kind = clk_none;
}
gl_kind = lvalue_kind (expr);
else if (CLASS_TYPE_P (from)
|| TREE_CODE (from) == ARRAY_TYPE)
gl_kind = clk_class;
else
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;
if ((gl_kind & clk_bitfield) != 0)
@ -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
const and rvalue references to rvalues of compatible class type.
We should also do direct bindings for non-class xvalues. */
if (related_p
&& (gl_kind
|| (!(flags & LOOKUP_NO_TEMP_BIND)
&& (CLASS_TYPE_P (from)
|| TREE_CODE (from) == ARRAY_TYPE))))
if (related_p && gl_kind)
{
/* [dcl.init.ref]

View File

@ -11,7 +11,11 @@ struct A
int main()
{
const int &r = A().i;
{
const int &r = A().i;
if (d != 0)
return 1;
}
if (d != 1)
return 1;
}