Commit 5efef981 by Ollie Wild Committed by Ollie Wild

re PR c++/54197 (Lifetime of reference not properly extended)

2012-08-31  Ollie Wild  <aaw@google.com>

	PR c++/54197
	* gcc/cp/call.c (extend_ref_init_temps_1): Handle COMPOUND_EXPR trees.
	* gcc/testsuite/g++.dg/init/lifetime3.C: New test.

From-SVN: r190834
parent 03360965
2012-08-31 Ollie Wild <aaw@google.com>
PR c++/54197
* call.c (extend_ref_init_temps_1): Handle COMPOUND_EXPR trees.
2012-08-30 Jason Merrill <jason@redhat.com>
PR c++/50545
......
......@@ -8916,6 +8916,12 @@ extend_ref_init_temps_1 (tree decl, tree init, VEC(tree,gc) **cleanups)
tree sub = init;
tree *p;
STRIP_NOPS (sub);
if (TREE_CODE (sub) == COMPOUND_EXPR)
{
TREE_OPERAND (sub, 1)
= extend_ref_init_temps_1 (decl, TREE_OPERAND (sub, 1), cleanups);
return init;
}
if (TREE_CODE (sub) != ADDR_EXPR)
return init;
/* Deal with binding to a subobject. */
......
2012-08-31 Ollie Wild <aaw@google.com>
PR c++/54197
* g++.dg/init/lifetime3.C: New test.
2012-08-31 Martin Jambor <mjambor@suse.cz>
PR middle-end/54409
......
// PR c++/26714
// { dg-do run }
extern "C" void abort();
bool ok = false;
struct A {
A() { }
~A() { if (!ok) abort(); }
};
struct B {
static A foo() { return A(); }
};
B b_g;
struct scoped_ptr {
B* operator->() const { return &b_g; }
B* get() const { return &b_g; }
};
B *get() { return &b_g; }
int main()
{
scoped_ptr f;
const A& ref1 = f->foo();
const A& ref2 = f.get()->foo();
const A& ref3 = get()->foo();
const A& ref4 = B::foo();
B *pf = f.get();
const A& ref5 = pf->foo();
ok = true;
}
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