File tree Expand file tree Collapse file tree 2 files changed +70
-21
lines changed Expand file tree Collapse file tree 2 files changed +70
-21
lines changed Original file line number Diff line number Diff line change @@ -343,9 +343,13 @@ class BuildTreeVisitor : public RecursiveASTVisitor<BuildTreeVisitor> {
343
343
}
344
344
345
345
bool WalkUpFromTagDecl (TagDecl *C) {
346
- // Avoid building UnknownDeclaration here, syntatically 'struct X {}' and
347
- // similar are part of declaration specifiers and do not introduce a new
348
- // top-level declaration.
346
+ // FIXME: build the ClassSpecifier node.
347
+ if (C->isFreeStanding ()) {
348
+ // Class is a declaration specifier and needs a spanning declaration node.
349
+ Builder.foldNode (Builder.getRange (C),
350
+ new (allocator ()) syntax::SimpleDeclaration);
351
+ return true ;
352
+ }
349
353
return true ;
350
354
}
351
355
Original file line number Diff line number Diff line change @@ -590,6 +590,50 @@ namespace foo = a;
590
590
|-=
591
591
|-a
592
592
`-;
593
+ )txt" },
594
+ // Free-standing classes, must live inside a SimpleDeclaration.
595
+ {R"cpp(
596
+ sturct X;
597
+ struct X {};
598
+
599
+ struct Y *y1;
600
+ struct Y {} *y2;
601
+
602
+ struct {} *a1;
603
+ )cpp" ,
604
+ R"txt(
605
+ *: TranslationUnit
606
+ |-SimpleDeclaration
607
+ | |-sturct
608
+ | |-X
609
+ | `-;
610
+ |-SimpleDeclaration
611
+ | |-struct
612
+ | |-X
613
+ | |-{
614
+ | |-}
615
+ | `-;
616
+ |-SimpleDeclaration
617
+ | |-struct
618
+ | |-Y
619
+ | |-*
620
+ | |-y1
621
+ | `-;
622
+ |-SimpleDeclaration
623
+ | |-struct
624
+ | |-Y
625
+ | |-{
626
+ | |-}
627
+ | |-*
628
+ | |-y2
629
+ | `-;
630
+ `-SimpleDeclaration
631
+ |-struct
632
+ |-{
633
+ |-}
634
+ |-*
635
+ |-a1
636
+ `-;
593
637
)txt" },
594
638
{R"cpp(
595
639
namespace ns {}
@@ -646,24 +690,25 @@ template <class T> struct X {
646
690
| |-class
647
691
| `-T
648
692
|->
649
- |-struct
650
- |-X
651
- |-{
652
- |-UsingDeclaration
653
- | |-using
654
- | |-T
655
- | |-::
656
- | |-foo
657
- | `-;
658
- |-UsingDeclaration
659
- | |-using
660
- | |-typename
661
- | |-T
662
- | |-::
663
- | |-bar
664
- | `-;
665
- |-}
666
- `-;
693
+ `-SimpleDeclaration
694
+ |-struct
695
+ |-X
696
+ |-{
697
+ |-UsingDeclaration
698
+ | |-using
699
+ | |-T
700
+ | |-::
701
+ | |-foo
702
+ | `-;
703
+ |-UsingDeclaration
704
+ | |-using
705
+ | |-typename
706
+ | |-T
707
+ | |-::
708
+ | |-bar
709
+ | `-;
710
+ |-}
711
+ `-;
667
712
)txt" },
668
713
{R"cpp(
669
714
using type = int;
You can’t perform that action at this time.
0 commit comments