diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -6447,7 +6447,8 @@ ToFunc->setAccess(D->getAccess()); ToFunc->setLexicalDeclContext(LexicalDC); - LexicalDC->addDeclInternal(ToFunc); + if (D->getFriendObjectKind() == Decl::FOK_None) + LexicalDC->addDeclInternal(ToFunc); ASTImporterLookupTable *LT = Importer.SharedState->getLookupTable(); if (LT && !OldParamDC.empty()) { diff --git a/clang/test/Import/templated-friend/Inputs/T.cpp b/clang/test/Import/templated-friend/Inputs/T.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Import/templated-friend/Inputs/T.cpp @@ -0,0 +1,3 @@ +template struct A { + template friend void f(); +}; diff --git a/clang/test/Import/templated-friend/test.cpp b/clang/test/Import/templated-friend/test.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Import/templated-friend/test.cpp @@ -0,0 +1,5 @@ +// RUN: clang-import-test -import %S/Inputs/T.cpp -expression %s + +void expr() { + A a; +}