c++: class-head parsing and CPP_TEMPLATE_ID access [PR108275]
commit12b0d35ec52375da5652d2b8da74083ab700b9d7
authorPatrick Palka <ppalka@redhat.com>
Thu, 5 Jan 2023 19:21:34 +0000 (5 14:21 -0500)
committerPatrick Palka <ppalka@redhat.com>
Thu, 5 Jan 2023 19:21:34 +0000 (5 14:21 -0500)
treeecadf0ab0e7a9d7b070a5f23921d475de7f1fcb9
parent9807c31af91326988d083436483f9577296e1f9a
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.
gcc/cp/parser.cc
gcc/testsuite/g++.dg/parse/access14.C [new file with mode: 0644]