aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2018-05-22 23:52:56 -0400
committerJason Merrill <jason@gcc.gnu.org>2018-05-22 23:52:56 -0400
commit3423a64d46de09a8625db4c2ec2b6a1586f40c56 (patch)
tree1103b7b062ffb9fbd4bd8125e720a5cd594684c5 /gcc
parent0d2e69cb3c08f44a15415fb264bf438bb8c9707c (diff)
downloadgcc-3423a64d46de09a8625db4c2ec2b6a1586f40c56.zip
gcc-3423a64d46de09a8625db4c2ec2b6a1586f40c56.tar.gz
gcc-3423a64d46de09a8625db4c2ec2b6a1586f40c56.tar.bz2
PR c++/81420 - not extending temporary lifetime.
* call.c (extend_ref_init_temps_1): Handle ARRAY_REF. * class.c (build_base_path): Avoid redundant move of an rvalue. From-SVN: r260563
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog4
-rw-r--r--gcc/cp/call.c4
-rw-r--r--gcc/cp/class.c2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/temp-extend1.C19
4 files changed, 27 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index ce22731..ee7361b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,9 @@
2018-05-22 Jason Merrill <jason@redhat.com>
+ PR c++/81420 - not extending temporary lifetime.
+ * call.c (extend_ref_init_temps_1): Handle ARRAY_REF.
+ * class.c (build_base_path): Avoid redundant move of an rvalue.
+
PR c++/85866 - error with .* in default template arg.
* pt.c (tsubst_copy_and_build): Handle partial instantiation.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 1df4d14..c100a92 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -11061,7 +11061,9 @@ extend_ref_init_temps_1 (tree decl, tree init, vec<tree, va_gc> **cleanups)
if (TREE_CODE (sub) != ADDR_EXPR)
return init;
/* Deal with binding to a subobject. */
- for (p = &TREE_OPERAND (sub, 0); TREE_CODE (*p) == COMPONENT_REF; )
+ for (p = &TREE_OPERAND (sub, 0);
+ (TREE_CODE (*p) == COMPONENT_REF
+ || TREE_CODE (*p) == ARRAY_REF); )
p = &TREE_OPERAND (*p, 0);
if (TREE_CODE (*p) == TARGET_EXPR)
{
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index a9a0fa9..25753d4 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -426,7 +426,7 @@ build_base_path (enum tree_code code,
{
expr = cp_build_fold_indirect_ref (expr);
expr = build_simple_base_path (expr, binfo);
- if (rvalue)
+ if (rvalue && lvalue_p (expr))
expr = move (expr);
if (want_pointer)
expr = build_address (expr);
diff --git a/gcc/testsuite/g++.dg/cpp0x/temp-extend1.C b/gcc/testsuite/g++.dg/cpp0x/temp-extend1.C
new file mode 100644
index 0000000..639f945
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/temp-extend1.C
@@ -0,0 +1,19 @@
+// PR c++/81420
+// { dg-do run { target c++11 } }
+
+int d;
+
+struct A
+{
+ int i[2];
+ ~A() { ++d; };
+};
+
+struct B: A {};
+
+int main()
+{
+ const int &r = B().i[0];
+ if (d != 0)
+ __builtin_abort();
+}