[PATCH] D142607: [clang][ASTImporter] Handle UsingType in friend declarations.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 26 00:59:18 PST 2023
balazske created this revision.
Herald added subscribers: steakhal, martong, gamesh411, Szelethus, dkrupp.
Herald added a reviewer: a.sidorin.
Herald added a reviewer: shafik.
Herald added a project: All.
balazske requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
ASTImporterLookupTable did not handle correctly friend declarations
where the friend type is an UsingType (type of a declaration that
comes from an using-declaration). The problem is fixed by handling
it in the same way as a friend with TypedefType.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D142607
Files:
clang/lib/AST/ASTImporterLookupTable.cpp
clang/unittests/AST/ASTImporterTest.cpp
Index: clang/unittests/AST/ASTImporterTest.cpp
===================================================================
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -5160,6 +5160,39 @@
EXPECT_EQ(Res.count(Alias), 1u);
}
+TEST_P(ASTImporterLookupTableTest,
+ LookupFindsFriendClassDeclWithUsingTypeDoesNotAssert) {
+ TranslationUnitDecl *ToTU = getToTuDecl(
+ R"(
+ namespace a {
+ namespace b { class InnerClass; }
+ using b::InnerClass;
+ }
+ class B {
+ friend a::InnerClass;
+ };
+ )",
+ Lang_CXX11);
+
+ // ASTImporterLookupTable constructor handles friend with using-type without
+ // asserts.
+ ASTImporterLookupTable LT(*ToTU);
+
+ auto *Using = FirstDeclMatcher<UsingDecl>().match(
+ ToTU, usingDecl(hasName("InnerClass")));
+ DeclarationName Name = Using->getDeclName();
+ auto Res = LT.lookup(ToTU, Name);
+ EXPECT_EQ(Res.size(), 0u);
+ auto *NsA = FirstDeclMatcher<NamespaceDecl>().match(
+ ToTU, namespaceDecl(hasName("a")));
+ auto *RecordB = FirstDeclMatcher<CXXRecordDecl>().match(
+ ToTU, cxxRecordDecl(hasName("B")));
+ auto Res1 = LT.lookup(NsA, Name);
+ EXPECT_EQ(Res1.count(Using), 1u);
+ auto Res2 = LT.lookup(RecordB, Name);
+ EXPECT_EQ(Res2.size(), 0u);
+}
+
TEST_P(ASTImporterLookupTableTest, LookupFindsFwdFriendClassTemplateDecl) {
TranslationUnitDecl *ToTU = getToTuDecl(
R"(
Index: clang/lib/AST/ASTImporterLookupTable.cpp
===================================================================
--- clang/lib/AST/ASTImporterLookupTable.cpp
+++ clang/lib/AST/ASTImporterLookupTable.cpp
@@ -67,6 +67,8 @@
} else if (isa<TypedefType>(Ty)) {
// We do not put friend typedefs to the lookup table because
// ASTImporter does not organize typedefs into redecl chains.
+ } else if (isa<UsingType>(Ty)) {
+ // Similar to TypedefType, not putting into lookup table.
} else {
llvm_unreachable("Unhandled type of friend class");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D142607.492351.patch
Type: text/x-patch
Size: 2068 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230126/afefc86f/attachment.bin>
More information about the cfe-commits
mailing list