Skip to content

Commit e3a6492

Browse files
committed
Reject nested name specifiers in C mode
Signed-off-by: Roberto Raggi <[email protected]>
1 parent bdb8f5e commit e3a6492

File tree

2 files changed

+6
-15
lines changed

2 files changed

+6
-15
lines changed

src/parser/cxx/parser.cc

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,6 @@ auto Parser::prec(TokenKind tk) -> Parser::Prec {
247247
} // switch
248248
}
249249

250-
auto Parser::is_c() const -> bool {
251-
return unit->language() == LanguageKind::kC;
252-
}
253-
254-
auto Parser::is_cxx() const -> bool {
255-
return unit->language() == LanguageKind::kCXX;
256-
}
257-
258250
auto Parser::LA(int n) const -> const Token& {
259251
return unit->tokenAt(SourceLocation(cursor_ + n));
260252
}
@@ -1073,6 +1065,8 @@ auto Parser::parse_template_nested_name_specifier(
10731065
auto Parser::parse_nested_name_specifier(NestedNameSpecifierAST*& yyast,
10741066
NestedNameSpecifierContext ctx)
10751067
-> bool {
1068+
if (!is_parsing_cxx()) return false;
1069+
10761070
if (SourceLocation scopeLoc; match(TokenKind::T_COLON_COLON, scopeLoc)) {
10771071
auto ast = make_node<GlobalNestedNameSpecifierAST>(pool_);
10781072
yyast = ast;
@@ -1471,7 +1465,7 @@ auto Parser::parse_nested_expession(ExpressionAST*& yyast,
14711465

14721466
auto Parser::parse_fold_expression(ExpressionAST*& yyast,
14731467
const ExprContext& ctx) -> bool {
1474-
if (!is_cxx()) return false;
1468+
if (!is_parsing_cxx()) return false;
14751469

14761470
if (!lookat(TokenKind::T_LPAREN)) return false;
14771471

@@ -3524,7 +3518,7 @@ auto Parser::parse_for_statement(StatementAST*& yyast) -> bool {
35243518
SourceLocation colonLoc;
35253519

35263520
auto lookat_for_range_declaration = [&] {
3527-
if (!is_cxx()) return false;
3521+
if (!is_parsing_cxx()) return false;
35283522

35293523
LookaheadParser lookahead{this};
35303524

@@ -6070,7 +6064,7 @@ auto Parser::parse_initializer_list(List<ExpressionAST*>*& yyast,
60706064
auto Parser::lookat_designator() -> bool {
60716065
if (lookat(TokenKind::T_DOT)) return true;
60726066

6073-
if (is_c() && lookat(TokenKind::T_LBRACKET)) return true;
6067+
if (is_parsing_c() && lookat(TokenKind::T_LBRACKET)) return true;
60746068

60756069
return false;
60766070
}
@@ -6119,7 +6113,7 @@ auto Parser::parse_designated_initializer_clause(
61196113
*it = make_list_node(pool_, designator);
61206114
it = &(*it)->next;
61216115

6122-
if (is_c()) {
6116+
if (is_parsing_c()) {
61236117
while (lookat_designator()) {
61246118
DesignatorAST* designator = nullptr;
61256119
parse_designator(designator);

src/parser/cxx/parser.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -739,9 +739,6 @@ class Parser final {
739739
[[nodiscard]] auto parse_identifier_list(List<NameIdAST*>*& yyast) -> bool;
740740

741741
private:
742-
[[nodiscard]] auto is_c() const -> bool;
743-
[[nodiscard]] auto is_cxx() const -> bool;
744-
745742
[[nodiscard]] auto lookat(auto... tokens) {
746743
return lookatHelper(0, tokens...);
747744
}

0 commit comments

Comments
 (0)