summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraaw <aaw@138bc75d-0d04-0410-961f-82ee72b054a4>2012-08-31 15:47:29 +0000
committeraaw <aaw@138bc75d-0d04-0410-961f-82ee72b054a4>2012-08-31 15:47:29 +0000
commit63ade1d898927dcd4c9544d17bcd44688fb7d6a6 (patch)
tree589f7daabbc93367a0dc703715ace6fc0735ea07
parentf44ba3727388ceb1bb3ed7b1b4bcae6e1438898c (diff)
downloadgcc-63ade1d898927dcd4c9544d17bcd44688fb7d6a6.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@190834 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/call.c6
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/init/lifetime3.C37
4 files changed, 53 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 0bfcde7ecd8..5fb1b41c149 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 3915738e516..4d65b3e6ddd 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b8d48f8d371..2d3bf4dd61f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+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
diff --git a/gcc/testsuite/g++.dg/init/lifetime3.C b/gcc/testsuite/g++.dg/init/lifetime3.C
new file mode 100644
index 00000000000..d099699f868
--- /dev/null
+++ b/gcc/testsuite/g++.dg/init/lifetime3.C
@@ -0,0 +1,37 @@
+// 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;
+}