diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Serialization/ASTWriterDecl.cpp | 12 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/cxx-templates-a.h | 2 | ||||
-rw-r--r-- | clang/test/Modules/Inputs/cxx-templates-common.h | 6 | ||||
-rw-r--r-- | clang/test/Modules/cxx-templates.cpp | 4 |
4 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp b/clang/lib/Serialization/ASTWriterDecl.cpp index d83b3ede38e..3aeb89559e7 100644 --- a/clang/lib/Serialization/ASTWriterDecl.cpp +++ b/clang/lib/Serialization/ASTWriterDecl.cpp @@ -176,6 +176,18 @@ void ASTDeclWriter::VisitDecl(Decl *D) { Record.push_back(D->getAccess()); Record.push_back(D->isModulePrivate()); Record.push_back(Writer.inferSubmoduleIDFromLocation(D->getLocation())); + + // If this declaration injected a name into a context different from its + // lexical context, and that context is an imported namespace, we need to + // update its visible declarations to include this name. + // + // This happens when we instantiate a class with a friend declaration or a + // function with a local extern declaration, for instance. + if (D->isOutOfLine()) { + auto *NS = dyn_cast<NamespaceDecl>(D->getDeclContext()->getRedeclContext()); + if (NS && NS->isFromASTFile()) + Writer.AddUpdatedDeclContext(NS); + } } void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { diff --git a/clang/test/Modules/Inputs/cxx-templates-a.h b/clang/test/Modules/Inputs/cxx-templates-a.h index 0b1614d3d9e..6ecc2ca4610 100644 --- a/clang/test/Modules/Inputs/cxx-templates-a.h +++ b/clang/test/Modules/Inputs/cxx-templates-a.h @@ -48,3 +48,5 @@ template<typename T> struct MergeSpecializations<T*> { template<> struct MergeSpecializations<char> { typedef int explicitly_specialized_in_a; }; + +void InstantiateWithFriend(Std::WithFriend<int> wfi) {} diff --git a/clang/test/Modules/Inputs/cxx-templates-common.h b/clang/test/Modules/Inputs/cxx-templates-common.h index 40a11e20b4f..77e3ddda36f 100644 --- a/clang/test/Modules/Inputs/cxx-templates-common.h +++ b/clang/test/Modules/Inputs/cxx-templates-common.h @@ -9,3 +9,9 @@ struct DefinedInCommon { template<typename T> struct CommonTemplate { enum E { a = 1, b = 2, c = 3 }; }; + +namespace Std { + template<typename T> struct WithFriend { + friend bool operator!=(const WithFriend &A, const WithFriend &B) { return false; } + }; +} diff --git a/clang/test/Modules/cxx-templates.cpp b/clang/test/Modules/cxx-templates.cpp index a1543888c39..d9331938acb 100644 --- a/clang/test/Modules/cxx-templates.cpp +++ b/clang/test/Modules/cxx-templates.cpp @@ -117,6 +117,10 @@ void testImplicitSpecialMembers(SomeTemplate<char[1]> &a, c = d; } +bool testFriendInClassTemplate(Std::WithFriend<int> wfi) { + return wfi != wfi; +} + // CHECK-GLOBAL: DeclarationName 'f' // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f' |