[PATCH] D142607: [clang][ASTImporter] Handle UsingType in friend declarations.
Balázs Kéri via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Jan 30 01:06:53 PST 2023
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe31ee6417c33: [clang][ASTImporter] Handle UsingType in friend declarations. (authored by balazske).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D142607/new/
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
@@ -5180,6 +5180,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.493227.patch
Type: text/x-patch
Size: 2068 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230130/0d7f247a/attachment.bin>
More information about the cfe-commits
mailing list