diff --git a/clang/lib/AST/ASTImporterLookupTable.cpp b/clang/lib/AST/ASTImporterLookupTable.cpp --- a/clang/lib/AST/ASTImporterLookupTable.cpp +++ b/clang/lib/AST/ASTImporterLookupTable.cpp @@ -67,6 +67,8 @@ } else if (isa(Ty)) { // We do not put friend typedefs to the lookup table because // ASTImporter does not organize typedefs into redecl chains. + } else if (isa(Ty)) { + // Similar to TypedefType, not putting into lookup table. } else { llvm_unreachable("Unhandled type of friend class"); } diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/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().match( + ToTU, usingDecl(hasName("InnerClass"))); + DeclarationName Name = Using->getDeclName(); + auto Res = LT.lookup(ToTU, Name); + EXPECT_EQ(Res.size(), 0u); + auto *NsA = FirstDeclMatcher().match( + ToTU, namespaceDecl(hasName("a"))); + auto *RecordB = FirstDeclMatcher().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"(