Skip to content

Commit 4797f01

Browse files
committed
c++: class nttp ICE
The new testcase from P2308 crashed trying to expand 'this' without an object to refer to, because we stripped the TARGET_EXPR in create_template_parm_object. So let's leave it on for giving an error. gcc/cp/ChangeLog: * pt.cc (create_template_parm_object): Pass TARGET_EXPR to cxx_constant_value. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/nontype-class64.C: New test.
1 parent 0535c20 commit 4797f01

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

gcc/cp/pt.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -7308,14 +7308,15 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain)
73087308
static tree
73097309
create_template_parm_object (tree expr, tsubst_flags_t complain)
73107310
{
7311+
tree orig = expr;
73117312
if (TREE_CODE (expr) == TARGET_EXPR)
73127313
expr = TARGET_EXPR_INITIAL (expr);
73137314

73147315
if (!TREE_CONSTANT (expr))
73157316
{
73167317
if ((complain & tf_error)
7317-
&& require_rvalue_constant_expression (expr))
7318-
cxx_constant_value (expr);
7318+
&& require_rvalue_constant_expression (orig))
7319+
cxx_constant_value (orig);
73197320
return error_mark_node;
73207321
}
73217322
if (invalid_tparm_referent_p (TREE_TYPE (expr), expr, complain))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Testcase from P2308R1
2+
// { dg-do compile { target c++20 } }
3+
4+
template<auto n> struct B { /* ... */ };
5+
B<5> b1; // OK, template parameter type is int
6+
B<'a'> b2; // OK, template parameter type is char
7+
B<2.5> b3; // OK, template parameter type is double
8+
B<void(0)> b4; // { dg-error "void" }
9+
10+
template<int i> struct C { /* ... */ };
11+
C<{ 42 }> c1; // OK
12+
13+
struct J1 {
14+
J1 *self=this;
15+
};
16+
B<J1{}> j1; // { dg-error "not a constant expression" }
17+
18+
struct J2 {
19+
J2 *self=this;
20+
constexpr J2() {}
21+
constexpr J2(const J2&) {}
22+
};
23+
B<J2{}> j2; // { dg-error "" }

0 commit comments

Comments
 (0)