Skip to content

Commit 184e1dd

Browse files
committed
fix: Parse of class specifiers in defining type ids
1 parent 93f32c2 commit 184e1dd

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/parser/cxx/parser.cc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,7 +3529,8 @@ auto Parser::parse_alias_declaration(
35293529

35303530
TypeIdAST* typeId = nullptr;
35313531

3532-
if (!parse_defining_type_id(typeId)) parse_error("expected a type id");
3532+
if (!parse_defining_type_id(typeId, templateDeclarations))
3533+
parse_error("expected a type id");
35333534

35343535
SourceLocation semicolonLoc;
35353536

@@ -5232,10 +5233,12 @@ auto Parser::parse_type_id(TypeIdAST*& yyast) -> bool {
52325233
return true;
52335234
}
52345235

5235-
auto Parser::parse_defining_type_id(TypeIdAST*& yyast) -> bool {
5236+
auto Parser::parse_defining_type_id(
5237+
TypeIdAST*& yyast,
5238+
const std::vector<TemplateDeclarationAST*>& templateDeclarations) -> bool {
52365239
DeclSpecs specs;
52375240

5238-
specs.no_class_or_enum_specs = true;
5241+
if (!templateDeclarations.empty()) specs.no_class_or_enum_specs = true;
52395242

52405243
List<SpecifierAST*>* typeSpecifierList = nullptr;
52415244

src/parser/cxx/parser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,9 @@ class Parser final {
411411
[[nodiscard]] auto parse_ref_qualifier(SourceLocation& refLoc) -> bool;
412412
[[nodiscard]] auto parse_declarator_id(CoreDeclaratorAST*& yyast) -> bool;
413413
[[nodiscard]] auto parse_type_id(TypeIdAST*& yyast) -> bool;
414-
[[nodiscard]] auto parse_defining_type_id(TypeIdAST*& yyast) -> bool;
414+
[[nodiscard]] auto parse_defining_type_id(
415+
TypeIdAST*& yyast,
416+
const std::vector<TemplateDeclarationAST*>& templateDeclarations) -> bool;
415417
[[nodiscard]] auto parse_abstract_declarator(DeclaratorAST*& yyast) -> bool;
416418
[[nodiscard]] auto parse_ptr_abstract_declarator(DeclaratorAST*& yyast)
417419
-> bool;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %cxx -verify -ast-dump %s | %filecheck %s --match-full-lines
2+
3+
using Pair = struct {
4+
int a, b;
5+
};
6+
// clang-format off
7+
// CHECK:translation-unit
8+
// CHECK-NEXT: declaration-list
9+
// CHECK-NEXT: alias-declaration
10+
// CHECK-NEXT: identifier: Pair
11+
// CHECK-NEXT: type-id: type-id
12+
// CHECK-NEXT: type-specifier-list
13+
// CHECK-NEXT: class-specifier
14+
// CHECK-NEXT: class-key: struct
15+
// CHECK-NEXT: declaration-list
16+
// CHECK-NEXT: simple-declaration
17+
// CHECK-NEXT: decl-specifier-list
18+
// CHECK-NEXT: integral-type-specifier
19+
// CHECK-NEXT: specifier: int
20+
// CHECK-NEXT: init-declarator-list
21+
// CHECK-NEXT: init-declarator
22+
// CHECK-NEXT: declarator: declarator
23+
// CHECK-NEXT: core-declarator: id-declarator
24+
// CHECK-NEXT: declarator-id: id-expression
25+
// CHECK-NEXT: unqualified-id: name-id
26+
// CHECK-NEXT: identifier: a
27+
// CHECK-NEXT: init-declarator
28+
// CHECK-NEXT: declarator: declarator
29+
// CHECK-NEXT: core-declarator: id-declarator
30+
// CHECK-NEXT: declarator-id: id-expression
31+
// CHECK-NEXT: unqualified-id: name-id
32+
// CHECK-NEXT: identifier: b
33+
// CHECK-NEXT: declarator: declarator

0 commit comments

Comments
 (0)