]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: ICE in build_deduction_guide for invalid template [PR105760]
authorSimon Martin <simon-l.martin@laposte.net>
Mon, 6 May 2024 13:20:10 +0000 (15:20 +0200)
committerJason Merrill <jason@redhat.com>
Tue, 14 May 2024 22:08:06 +0000 (18:08 -0400)
We currently ICE upon the following invalid snippet because we fail to
properly handle tsubst_arg_types returning error_mark_node in
build_deduction_guide.

== cut ==
template<class... Ts, class>
struct A { A(Ts...); };
A a;
== cut ==

This patch fixes this, and has been successfully tested on x86_64-pc-linux-gnu.

PR c++/105760

gcc/cp/ChangeLog:

* pt.cc (build_deduction_guide): Check for error_mark_node
result from tsubst_arg_types.

gcc/testsuite/ChangeLog:

* g++.dg/parse/error66.C: New test.

gcc/cp/pt.cc
gcc/testsuite/g++.dg/parse/error66.C [new file with mode: 0644]

index 4b71e199d27f4ceacf4b045a558d61a774cca19a..32640f8e946d346f3043326aab3dd850dfe0c7bb 100644 (file)
@@ -30031,6 +30031,8 @@ build_deduction_guide (tree type, tree ctor, tree outer_args, tsubst_flags_t com
             references to members of an unknown specialization.  */
          cp_evaluated ev;
          fparms = tsubst_arg_types (fparms, targs, NULL_TREE, complain, ctor);
+        if (fparms == error_mark_node)
+          ok = false;
          fargs = tsubst (fargs, targs, complain, ctor);
          if (ci)
            {
diff --git a/gcc/testsuite/g++.dg/parse/error66.C b/gcc/testsuite/g++.dg/parse/error66.C
new file mode 100644 (file)
index 0000000..82f4b8b
--- /dev/null
@@ -0,0 +1,6 @@
+// PR c++/105760
+// { dg-do compile { target c++17 } }
+
+template<class... Ts, class> // { dg-error "must be at the end of the template parameter list" }
+struct A { A(Ts...); };
+A a;