From f5c211a55a2cd7fec4f45668e8e39c0d59c5aba5 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sun, 23 Mar 2014 02:30:01 +0000 Subject: [PATCH] If a template instantation introduces a name into a namespace, we need to write out a visible update record for that namespace even if it was never declared in this module. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204554 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTWriterDecl.cpp | 12 ++++++++++++ test/Modules/Inputs/cxx-templates-a.h | 2 ++ test/Modules/Inputs/cxx-templates-common.h | 6 ++++++ test/Modules/cxx-templates.cpp | 4 ++++ 4 files changed, 24 insertions(+) diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index d83b3ede38..3aeb89559e 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/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(D->getDeclContext()->getRedeclContext()); + if (NS && NS->isFromASTFile()) + Writer.AddUpdatedDeclContext(NS); + } } void ASTDeclWriter::VisitTranslationUnitDecl(TranslationUnitDecl *D) { diff --git a/test/Modules/Inputs/cxx-templates-a.h b/test/Modules/Inputs/cxx-templates-a.h index 0b1614d3d9..6ecc2ca461 100644 --- a/test/Modules/Inputs/cxx-templates-a.h +++ b/test/Modules/Inputs/cxx-templates-a.h @@ -48,3 +48,5 @@ template struct MergeSpecializations { template<> struct MergeSpecializations { typedef int explicitly_specialized_in_a; }; + +void InstantiateWithFriend(Std::WithFriend wfi) {} diff --git a/test/Modules/Inputs/cxx-templates-common.h b/test/Modules/Inputs/cxx-templates-common.h index 40a11e20b4..77e3ddda36 100644 --- a/test/Modules/Inputs/cxx-templates-common.h +++ b/test/Modules/Inputs/cxx-templates-common.h @@ -9,3 +9,9 @@ struct DefinedInCommon { template struct CommonTemplate { enum E { a = 1, b = 2, c = 3 }; }; + +namespace Std { + template struct WithFriend { + friend bool operator!=(const WithFriend &A, const WithFriend &B) { return false; } + }; +} diff --git a/test/Modules/cxx-templates.cpp b/test/Modules/cxx-templates.cpp index a1543888c3..d9331938ac 100644 --- a/test/Modules/cxx-templates.cpp +++ b/test/Modules/cxx-templates.cpp @@ -117,6 +117,10 @@ void testImplicitSpecialMembers(SomeTemplate &a, c = d; } +bool testFriendInClassTemplate(Std::WithFriend wfi) { + return wfi != wfi; +} + // CHECK-GLOBAL: DeclarationName 'f' // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f' // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f' -- 2.40.0