c++: fix template parm count leak
authorNathan Sidwell <nathan@acm.org>
Tue, 4 Aug 2020 16:24:02 +0000 (09:24 -0700)
committerNathan Sidwell <nathan@acm.org>
Tue, 4 Aug 2020 16:32:18 +0000 (09:32 -0700)
commit0f4f9bc12201c9cda9558295a4fef58fe0246b44
tree0fe04fa020cb1b07bb207d25f0ceaac11bec9ef9
parent35ffd4d16d7e3dbba297da788414a673530b7817
c++: fix template parm count leak

I noticed that we could leak parser->num_template_parameter_lists with
erroneous specializations.  We'd increment, notice a problem and then
bail out.  This refactors cp_parser_explicit_specialization to avoid
that code path.  A couple of tests get different diagnostics because
of the fix.  pr39425 then goes to unbounded template instantiation
and exceeds the implementation limit.

gcc/cp/
* parser.c (cp_parser_explicit_specialization): Refactor
to avoid leak of num_template_parameter_lists value.
gcc/testsuite/
* g++.dg/template/pr39425.C: Adjust errors, (unbounded
template recursion).
* g++.old-deja/g++.pt/spec20.C: Remove fallout diagnostics.
gcc/cp/parser.c
gcc/testsuite/g++.dg/template/pr39425.C
gcc/testsuite/g++.old-deja/g++.pt/spec20.C