public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-4999] c++: Error recovery in merge_default_template_args [PR108206]
@ 2023-01-04 17:43 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2023-01-04 17:43 UTC (permalink / raw)
  To: gcc-cvs

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

commit r13-4999-gfc349931adcf1024ee95e0a0cd98cf4a41996093
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Wed Jan 4 18:42:31 2023 +0100

    c++: Error recovery in merge_default_template_args [PR108206]
    
    We ICE on the following testcase during error recovery, both new_parm
    and old_parm are error_mark_node, the ICE is on
              error ("redefinition of default argument for %q+#D", new_parm);
              inform (DECL_SOURCE_LOCATION (old_parm),
                      "original definition appeared here");
    where we don't print anything useful for new_parm and ICE trying to
    access DECL_SOURCE_LOCATION of old_parm.  I think we shouldn't diagnose
    anything when either of the parms is erroneous, GCC 11 before
    merge_default_template_args has been added was doing
          if (TREE_VEC_ELT (tmpl_parms, i) == error_mark_node
              || TREE_VEC_ELT (parms, i) == error_mark_node)
            continue;
    
          tmpl_parm = TREE_VALUE (TREE_VEC_ELT (tmpl_parms, i));
          if (error_operand_p (tmpl_parm))
            return false;
    in redeclare_class_template.
    
    2023-01-04  Jakub Jelinek  <jakub@redhat.com>
    
            PR c++/108206
            * decl.cc (merge_default_template_args): Return false if either
            new_parm or old_parm are erroneous.
    
            * g++.dg/template/pr108206.C: New test.

Diff:
---
 gcc/cp/decl.cc                           | 2 ++
 gcc/testsuite/g++.dg/template/pr108206.C | 5 +++++
 2 files changed, 7 insertions(+)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index 3c0355a1c39..66e7d9ff50e 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -1556,6 +1556,8 @@ merge_default_template_args (tree new_parms, tree old_parms, bool class_p)
       tree old_parm = TREE_VALUE (TREE_VEC_ELT (old_parms, i));
       tree& new_default = TREE_PURPOSE (TREE_VEC_ELT (new_parms, i));
       tree& old_default = TREE_PURPOSE (TREE_VEC_ELT (old_parms, i));
+      if (error_operand_p (new_parm) || error_operand_p (old_parm))
+	return false;
       if (new_default != NULL_TREE && old_default != NULL_TREE)
 	{
 	  auto_diagnostic_group d;
diff --git a/gcc/testsuite/g++.dg/template/pr108206.C b/gcc/testsuite/g++.dg/template/pr108206.C
new file mode 100644
index 00000000000..9362d261bea
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/pr108206.C
@@ -0,0 +1,5 @@
+// PR c++/108206
+// { dg-do compile { target c++11 } }
+
+template <X x, typename T1> void foo (T1);	// { dg-error "'X' has not been declared" }
+template <X x, typename T2> void foo (T2);	// { dg-error "'X' has not been declared" }

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

only message in thread, other threads:[~2023-01-04 17:43 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-04 17:43 [gcc r13-4999] c++: Error recovery in merge_default_template_args [PR108206] Jakub Jelinek

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