public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-6989] c++: ICE with loopy var tmpl auto deduction [PR109300]
@ 2023-04-03 22:50 Patrick Palka
  0 siblings, 0 replies; only message in thread
From: Patrick Palka @ 2023-04-03 22:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:c37ed38ada788ae410c48ec6d8c9b5d9f32ab8cf

commit r13-6989-gc37ed38ada788ae410c48ec6d8c9b5d9f32ab8cf
Author: Patrick Palka <ppalka@redhat.com>
Date:   Mon Apr 3 18:49:37 2023 -0400

    c++: ICE with loopy var tmpl auto deduction [PR109300]
    
    Now that we resolve non-dependent variable template-ids ahead of time,
    cp_finish_decl needs to handle a new invalid situation: we can end up
    trying to instantiate a variable template with deduced type before we
    fully parsed its initializer.
    
            PR c++/109300
    
    gcc/cp/ChangeLog:
    
            * decl.cc (cp_finish_decl): Diagnose ordinary auto deduction
            with no initializer, instead of asserting.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/cpp1y/var-templ79.C: New test.

Diff:
---
 gcc/cp/decl.cc                           | 15 ++++++++++++++-
 gcc/testsuite/g++.dg/cpp1y/var-templ79.C |  5 +++++
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 20b980f68c8..5369714f9b3 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -8276,7 +8276,20 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
 	      return;
 	    }
 
-	  gcc_assert (CLASS_PLACEHOLDER_TEMPLATE (auto_node));
+	  if (CLASS_PLACEHOLDER_TEMPLATE (auto_node))
+	    /* Class deduction with no initializer is OK.  */;
+	  else
+	    {
+	      /* Ordinary auto deduction without an initializer, a situation
+		 which grokdeclarator already detects and rejects for the most
+		 part.  But we can still get here if we're instantiating a
+		 variable template before we've fully parsed (and attached) its
+		 initializer, e.g. template<class> auto x = x<int>;  */
+	      error_at (DECL_SOURCE_LOCATION (decl),
+			"declaration of %q#D has no initializer", decl);
+	      TREE_TYPE (decl) = error_mark_node;
+	      return;
+	    }
 	}
       d_init = init;
       if (d_init)
diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ79.C b/gcc/testsuite/g++.dg/cpp1y/var-templ79.C
new file mode 100644
index 00000000000..3c0d276153a
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/var-templ79.C
@@ -0,0 +1,5 @@
+// PR c++/109300
+// { dg-do compile { target c++14 } }
+
+template<class>
+auto x = x<int>; // { dg-error "" }

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

only message in thread, other threads:[~2023-04-03 22:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-03 22:50 [gcc r13-6989] c++: ICE with loopy var tmpl auto deduction [PR109300] Patrick Palka

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).