c++: class-head parsing and CPP_TEMPLATE_ID access [PR108275]
When tentatively parsing what is really an elaborated-type-specifier
containing a template-id first as a class-specifier, we may form a
CPP_TEMPLATE_ID token that later gets reused by the fallback parse if
the tentative parse fails. These special tokens also capture the access
checks that have been deferred while parsing the template-id. But here
we form such a token when the access check state is dk_no_check, and so
the token captures no access checks. This effectively bypasses access
checking for the template-id during the subsequent parse as an
elaborated-type-specifier.
This patch fixes this by using dk_deferred instead of dk_no_check when
parsing the class name of a class-head.
PR c++/108275
gcc/cp/ChangeLog:
* parser.cc (cp_parser_class_head): Use dk_deferred instead of
dk_no_check when parsing the class name.
gcc/testsuite/ChangeLog:
* g++.dg/parse/access14.C: New test.