Skip to content

Commit a9e9f77

Browse files
committed
c++: consteval propagation and templates [PR115986]
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.
1 parent 3129a2e commit a9e9f77

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

gcc/cp/cp-gimplify.cc

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ static GTY(()) hash_set<tree> *deferred_escalating_exprs;
5353
static void
5454
remember_escalating_expr (tree t)
5555
{
56+
if (uses_template_parms (t))
57+
/* Templates don't escalate, and cp_fold_immediate can get confused by
58+
other template trees in the function body (c++/115986). */
59+
return;
5660
if (!deferred_escalating_exprs)
5761
deferred_escalating_exprs = hash_set<tree>::create_ggc (37);
5862
deferred_escalating_exprs->add (t);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// PR c++/115986
2+
// { dg-do compile { target c++20 } }
3+
4+
template <typename T>
5+
constexpr int b(T) {
6+
return 0;
7+
}
8+
consteval __uint128_t operator"" _c(const char*) { return 0; }
9+
constexpr char e() {
10+
long f = true ? 0 : b(long(1));
11+
return b(f);
12+
}
13+
template <typename>
14+
void d() {
15+
0_c;
16+
static_assert(e());
17+
}

0 commit comments

Comments
 (0)