[PR c++/84610,84642] recover from implicit template parms gracefully
commit70a32e4934cfbc26aee57bbf2ea7d8ceadd74a45
authoraoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Mar 2018 22:08:19 +0000 (21 22:08 +0000)
committeraoliva <aoliva@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 21 Mar 2018 22:08:19 +0000 (21 22:08 +0000)
treed4665d99cdd00d61e51fb107e3801bf4414225e5
parent86f1f5d13acb431eb5e30133161bcb146c6d0ad7
[PR c++/84610,84642] recover from implicit template parms gracefully

If we get a parse error during an attempted fully implicit function
template parse, and need to skip to the end of the statement or block,
we may discard the function parms scope rather than the enclosing
injected implicit template parms scope.  If we rollback a tentative
parse and try something else, we'll no longer be in a function parms
scope, but rather in a template parms scope, but we may still attempt
to synthesize implicit template parms and then fail the assert that
checks we're in a function parms scope.

This patch introduces an alternative to
finish_fully_implicit_template_p, to be used during error recovery,
that floats the implicit template parm scope to the top so that it
gets discarded as we finish and discard the failed implicit template
data, while other scopes are retained as expected.  It also clears the
implicit template parser data as we finish the template, so that it
doesn't linger on referencing discarded or used scopes and parms.

for gcc/cp/ChangeLog

PR c++/84610
PR c++/84642
* parser.c (abort_fully_implicit_template_p): New.
(cp_parser_skip_to_end_of_statement): Use it.
(cp_parser_skip_to_end_of_block_or_statement): Likewise.
(finish_fully_implicit_template_p): Clear
implicit_template_parms and implicit_template_scope.

for  gcc/testsuite/ChangeLog

PR c++/84610
PR c++/84642
* g++.dg/cpp0x/pr84610.C: New.
* g++.dg/cpp0x/pr84642.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@258748 138bc75d-0d04-0410-961f-82ee72b054a4
gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/pr84610.C [new file with mode: 0644]
gcc/testsuite/g++.dg/cpp0x/pr84642.C [new file with mode: 0644]