public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-8873] c++: class nttp ICE
@ 2024-02-08  0:22 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2024-02-08  0:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:4797f0100b95802b2c043d64364ce9b77469a182

commit r14-8873-g4797f0100b95802b2c043d64364ce9b77469a182
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Feb 7 15:03:01 2024 -0500

    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.

Diff:
---
 gcc/cp/pt.cc                                 |  5 +++--
 gcc/testsuite/g++.dg/cpp2a/nontype-class64.C | 23 +++++++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index 903a4a1c3630..55c23b642bcc 100644
--- a/gcc/cp/pt.cc
+++ b/gcc/cp/pt.cc
@@ -7308,14 +7308,15 @@ invalid_tparm_referent_p (tree type, tree expr, tsubst_flags_t complain)
 static tree
 create_template_parm_object (tree expr, tsubst_flags_t complain)
 {
+  tree orig = expr;
   if (TREE_CODE (expr) == TARGET_EXPR)
     expr = TARGET_EXPR_INITIAL (expr);
 
   if (!TREE_CONSTANT (expr))
     {
       if ((complain & tf_error)
-	  && require_rvalue_constant_expression (expr))
-	cxx_constant_value (expr);
+	  && require_rvalue_constant_expression (orig))
+	cxx_constant_value (orig);
       return error_mark_node;
     }
   if (invalid_tparm_referent_p (TREE_TYPE (expr), expr, complain))
diff --git a/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C b/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C
new file mode 100644
index 000000000000..eb6489238f04
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp2a/nontype-class64.C
@@ -0,0 +1,23 @@
+// Testcase from P2308R1
+// { dg-do compile { target c++20 } }
+
+template<auto n> struct B { /* ... */ };
+B<5> b1;                        // OK, template parameter type is int
+B<'a'> b2;                      // OK, template parameter type is char
+B<2.5> b3;                      // OK, template parameter type is double
+B<void(0)> b4;		       // { dg-error "void" }
+
+template<int i> struct C { /* ... */ };
+C<{ 42 }> c1;  // OK
+
+struct J1 {
+  J1 *self=this;
+};
+B<J1{}> j1;  // { dg-error "not a constant expression" }
+
+struct J2 {
+  J2 *self=this;
+  constexpr J2() {}
+  constexpr J2(const J2&) {}
+};
+B<J2{}> j2;  // { dg-error "" }

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-08  0:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-08  0:22 [gcc r14-8873] c++: class nttp ICE Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).