]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: consteval propagation and templates [PR115986]
authorJason Merrill <jason@redhat.com>
Fri, 26 Jul 2024 21:20:18 +0000 (17:20 -0400)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sun, 28 Jul 2024 17:06:02 +0000 (19:06 +0200)
Here the call to e() makes us decide to check d() for escalation at EOF, but
while checking it we try to fold_immediate 0_c, and get confused by the
template trees.  Let's not mess with escalation for function templates.

PR c++/115986

gcc/cp/ChangeLog:

* cp-gimplify.cc (remember_escalating_expr): Skip function
templates.

gcc/testsuite/ChangeLog:

* g++.dg/cpp2a/consteval-prop21.C: New test.

gcc/cp/cp-gimplify.cc
gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C [new file with mode: 0644]

index e6629dea5fdc8963206ceb59ca3477bd1512f906..6a5e4cf62ca1573c2f3b1075b612ccf81ff252c8 100644 (file)
@@ -53,6 +53,10 @@ static GTY(()) hash_set<tree> *deferred_escalating_exprs;
 static void
 remember_escalating_expr (tree t)
 {
+  if (uses_template_parms (t))
+    /* Templates don't escalate, and cp_fold_immediate can get confused by
+       other template trees in the function body (c++/115986).  */
+    return;
   if (!deferred_escalating_exprs)
     deferred_escalating_exprs = hash_set<tree>::create_ggc (37);
   deferred_escalating_exprs->add (t);
diff --git a/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C b/gcc/testsuite/g++.dg/cpp2a/consteval-prop21.C
new file mode 100644 (file)
index 0000000..debbda4
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/115986
+// { dg-do compile { target c++20 } }
+
+template <typename T>
+constexpr int b(T) {
+  return 0;
+}
+consteval __uint128_t operator"" _c(const char*) { return 0; }
+constexpr char e() {
+  long f = true ? 0 : b(long(1));
+  return b(f);
+}
+template <typename>
+void d() {
+  0_c;
+  static_assert(e());
+}