https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123609
chzn at mail dot ustc.edu.cn <chzn at mail dot ustc.edu.cn> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |chzn at mail dot ustc.edu.cn
--- Comment #2 from chzn at mail dot ustc.edu.cn <chzn at mail dot ustc.edu.cn>
---
I try to delay parsing attributes in cp_parser_class_head until tentative parse
comitted.
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -30267,6 +30267,8 @@ cp_parser_class_head (cp_parser* parser,
type. */
num_templates = 0;
parser->colon_corrects_to_scope_p = false;
+ cp_token *attributes_start_token, *committed_start_token;
+ location_t committed_position;
/* Look for the class-key. */
class_key = cp_parser_class_key (parser);
@@ -30275,8 +30277,10 @@ cp_parser_class_head (cp_parser* parser,
location_t class_head_start_location = input_location;
- /* Parse the attributes. */
- attributes = cp_parser_attributes_opt (parser);
+ /* Delay parsing the attributes. */
+ attributes_start_token = cp_lexer_token_position (parser->lexer, false);
+ for (size_t i = 1, n = cp_parser_skip_attributes_opt (parser, 1); i < n;
++i)
+ cp_lexer_consume_token (parser->lexer);
/* If the next token is `::', that is invalid -- but sometimes
people do try to write:
@@ -30418,6 +30422,13 @@ cp_parser_class_head (cp_parser* parser,
/* At this point, we're going ahead with the class-specifier, even
if some other problem occurs. */
cp_parser_commit_to_tentative_parse (parser);
+ /* Parse the attributes. */
+ committed_start_token = cp_lexer_token_position (parser->lexer, false);
+ committed_position = input_location;
+ cp_lexer_set_token_position (parser->lexer, attributes_start_token);
+ attributes = cp_parser_attributes_opt (parser);
+ cp_lexer_set_token_position (parser->lexer, committed_start_token);
+ input_location = committed_position;
/* Issue the error about the overly-qualified name now. */
if (qualified_p)
{
It fix it, but fail on testsuites:
- c-c++-common/Wbidi-chars-ranges.c
- g++.dg/parse/alignas1.C
- g++.dg/modules/adhoc-1_b.C