c++: Push parms when late parsing default args
authorJason Merrill <jason@redhat.com>
Wed, 2 Dec 2020 22:11:48 +0000 (17:11 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 3 Dec 2020 03:15:54 +0000 (22:15 -0500)
commitc03a78d8f8cac3019e7bc67b6ae39f4edc61cf2c
treea91b22d64976926d88b622aa66919ff41cff528e
parent54f97a226a0d8b315aa1a0129df957a8bb3fdf65
c++: Push parms when late parsing default args

In this testcase we weren't catching the error in A::f because the parameter
'I' wasn't in scope, so the default argument for 'b' found the global
typedef I.  Fixed by pushing the parms before parsing.  This is a bit
complicated because pushdecl clears DECL_CHAIN; do_push_parm_decls deals
with this by nreversing first, but that doesn't work here because we only
want to push them one at a time; if we pushed all of them before parsing,
we'd wrongly reject A::g.

gcc/cp/ChangeLog:

* parser.c (cp_parser_primary_expression): Distinguish
parms from vars in error.
(cp_parser_late_parsing_default_args): Pushdecl parms
as we go.

gcc/testsuite/ChangeLog:

* g++.dg/parse/defarg17.C: New test.
gcc/cp/parser.c
gcc/testsuite/g++.dg/parse/defarg17.C [new file with mode: 0644]