]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: Unshare expressions from constexpr cache.
authorJason Merrill <jason@redhat.com>
Thu, 23 Jan 2020 20:45:36 +0000 (15:45 -0500)
committerJason Merrill <jason@redhat.com>
Fri, 24 Jan 2020 19:08:32 +0000 (14:08 -0500)
Another place we need to unshare cached expressions.

PR c++/92852 - ICE with generic lambda and reference var.
* constexpr.c (maybe_constant_value): Likewise.

gcc/cp/ChangeLog
gcc/cp/constexpr.c
gcc/testsuite/g++.dg/cpp1y/lambda-generic-ref1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp1z/decomp48.C

index b3008ffab2f51fa9b7e7f87019712f53ae061bcc..9961a6f7f64d2c38bb632d8371edb164e98698b4 100644 (file)
@@ -1,3 +1,8 @@
+2020-01-24  Jason Merrill  <jason@redhat.com>
+
+       PR c++/92852 - ICE with generic lambda and reference var.
+       * constexpr.c (maybe_constant_value): Likewise.
+
 2020-01-22  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
index e2ca305aaca0a6136ec739beaa2f76d80d65da84..f0d4cb5e8e77fa29578a69a158e700e929e90be5 100644 (file)
@@ -5582,7 +5582,7 @@ maybe_constant_value (tree t, tree decl, bool manifestly_const_eval)
   if (cv_cache == NULL)
     cv_cache = hash_map<tree, tree>::create_ggc (101);
   if (tree *cached = cv_cache->get (t))
-    return *cached;
+    return unshare_expr_without_location (*cached);
 
   r = cxx_eval_outermost_constant_expr (t, true, true, false, decl);
   gcc_checking_assert (r == t
diff --git a/gcc/testsuite/g++.dg/cpp1y/lambda-generic-ref1.C b/gcc/testsuite/g++.dg/cpp1y/lambda-generic-ref1.C
new file mode 100644 (file)
index 0000000..a96fa1c
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/92852
+// { dg-do compile { target c++14 } }
+
+struct S { int operator<<(const int &); } glob;
+void foo()
+{
+  S& message_stream = glob;
+  auto format = [&message_stream](auto && x)
+               { message_stream << x ; };
+  format(3);
+  format(4u);
+}
index 3c50b02a6c247165b45192a9b1912650ec795aeb..35413c79a9daf32906cd1bd34a008ac0037b7f8f 100644 (file)
@@ -18,7 +18,7 @@ f2 ()
 {
   S v {1, 2};
   auto& [s, t] = v;    // { dg-warning "structured bindings only available with" "" { target c++14_down } }
-  return s;            // { dg-warning "reference to local variable 'v' returned" "" { target *-*-* } .-1 }
+  return s;            // { dg-warning "reference to local variable 'v' returned" }
 }
 
 int &
@@ -33,7 +33,7 @@ f4 ()
 {
   int a[3] = {1, 2, 3};
   auto& [s, t, u] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
-  return s;            // { dg-warning "reference to local variable 'a' returned" "" { target *-*-* } .-1 }
+  return s;            // { dg-warning "reference to local variable 'a' returned" }
 }
 
 int &
@@ -78,7 +78,7 @@ f10 ()
 {
   S v {1, 2};
   auto& [s, t] = v;    // { dg-warning "structured bindings only available with" "" { target c++14_down } }
-  return &s;           // { dg-warning "address of local variable 'v' returned" "" { target *-*-* } .-1 }
+  return &s;           // { dg-warning "address of local variable 'v' returned" }
 }
 
 int *
@@ -93,7 +93,7 @@ f12 ()
 {
   int a[3] = {1, 2, 3};
   auto& [s, t, u] = a; // { dg-warning "structured bindings only available with" "" { target c++14_down } }
-  return &s;           // { dg-warning "address of local variable 'a' returned" "" { target *-*-* } .-1 }
+  return &s;           // { dg-warning "address of local variable 'a' returned" }
 }
 
 int *