Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1790,7 +1790,9 @@ void NamedDecl::printNestedNameSpecifier(raw_ostream &OS,
else
OS << *ND;
} else if (const auto *RD = dyn_cast<RecordDecl>(DC)) {
if (!RD->getIdentifier())
if (TypedefNameDecl *Typedef = RD->getTypedefNameForAnonDecl())
OS << Typedef->getIdentifier()->getName();
else if (!RD->getIdentifier())
OS << "(anonymous " << RD->getKindName() << ')';
else
OS << *RD;
Expand Down
19 changes: 19 additions & 0 deletions clang/unittests/AST/TypePrinterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,3 +341,22 @@ TEST(TypePrinter, NestedNameSpecifiers) {
Policy.AnonymousTagLocations = false;
}));
}

TEST(TypePrinter, NestedNameSpecifiersTypedef) {
constexpr char Code[] = R"cpp(
typedef union {
struct {
struct {
unsigned int baz;
} bar;
};
} foo;
)cpp";

ASSERT_TRUE(PrintedTypeMatches(
Code, {}, fieldDecl(hasName("bar"), hasType(qualType().bind("id"))),
"struct foo::(anonymous struct)::(unnamed)", [](PrintingPolicy &Policy) {
Policy.FullyQualifiedName = true;
Policy.AnonymousTagLocations = false;
}));
}
Loading