r204554 - If a template instantation introduces a name into a namespace, we need to write
Richard Smith
richard-llvm at metafoo.co.uk
Sat Mar 22 19:30:02 PDT 2014
Author: rsmith
Date: Sat Mar 22 21:30:01 2014
New Revision: 204554
URL: http://llvm.org/viewvc/llvm-project?rev=204554&view=rev
Log:
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.
Modified:
cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
cfe/trunk/test/Modules/Inputs/cxx-templates-a.h
cfe/trunk/test/Modules/Inputs/cxx-templates-common.h
cfe/trunk/test/Modules/cxx-templates.cpp
Modified: cfe/trunk/lib/Serialization/ASTWriterDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriterDecl.cpp?rev=204554&r1=204553&r2=204554&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTWriterDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriterDecl.cpp Sat Mar 22 21:30:01 2014
@@ -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) {
Modified: cfe/trunk/test/Modules/Inputs/cxx-templates-a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-a.h?rev=204554&r1=204553&r2=204554&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-a.h (original)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-a.h Sat Mar 22 21:30:01 2014
@@ -48,3 +48,5 @@ template<typename T> struct MergeSpecial
template<> struct MergeSpecializations<char> {
typedef int explicitly_specialized_in_a;
};
+
+void InstantiateWithFriend(Std::WithFriend<int> wfi) {}
Modified: cfe/trunk/test/Modules/Inputs/cxx-templates-common.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/cxx-templates-common.h?rev=204554&r1=204553&r2=204554&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/cxx-templates-common.h (original)
+++ cfe/trunk/test/Modules/Inputs/cxx-templates-common.h Sat Mar 22 21:30:01 2014
@@ -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; }
+ };
+}
Modified: cfe/trunk/test/Modules/cxx-templates.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/cxx-templates.cpp?rev=204554&r1=204553&r2=204554&view=diff
==============================================================================
--- cfe/trunk/test/Modules/cxx-templates.cpp (original)
+++ cfe/trunk/test/Modules/cxx-templates.cpp Sat Mar 22 21:30:01 2014
@@ -117,6 +117,10 @@ void testImplicitSpecialMembers(SomeTemp
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'
More information about the cfe-commits
mailing list