Message ID | 20160919120712.8930-1-patrick@parcs.ath.cx |
---|---|
State | New |
Headers | show |
> if (tree t = maybe_new_partial_specialization (type)) > { > + if (processing_template_parmlist) > + { > + /* Some syntactically invalid code can confuse the compiler into > + defining a specialization from inside a template parameter > + list. Bail out now so that we won't ICE later. */ > + gcc_assert (seen_error ()); > + return error_mark_node; > + } Rather than decide it's a specialization and then fail, let's avoid treating it as a specialization in the first place. I think we can add a processing_template_parmlist check at the top where we avoid trying to specialize lambdas. Jason
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 29d8beb..c1b3d5b 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -962,6 +962,14 @@ maybe_process_partial_specialization (tree type) if (tree t = maybe_new_partial_specialization (type)) { + if (processing_template_parmlist) + { + /* Some syntactically invalid code can confuse the compiler into + defining a specialization from inside a template parameter + list. Bail out now so that we won't ICE later. */ + gcc_assert (seen_error ()); + return error_mark_node; + } if (!check_specialization_namespace (CLASSTYPE_TI_TEMPLATE (t)) && !at_namespace_scope_p ()) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/template/error-recovery4.C b/gcc/testsuite/g++.dg/template/error-recovery4.C new file mode 100644 index 0000000..1725d87 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/error-recovery4.C @@ -0,0 +1,5 @@ +// PR c++/77639 + +template <class, int, class, int> struct B {}; +template <class T, int a, class U struct B<int, 2, char, 1> {}; // { dg-error "" } +B<int, 2, char, 1> i;