]> granicus.if.org Git - clang/commitdiff
If a template instantation introduces a name into a namespace, we need to write
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 23 Mar 2014 02:30:01 +0000 (02:30 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 23 Mar 2014 02:30:01 +0000 (02:30 +0000)
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
test/Modules/Inputs/cxx-templates-a.h
test/Modules/Inputs/cxx-templates-common.h
test/Modules/cxx-templates.cpp

index d83b3ede38e80b01ba8930ca520f5e21d75c4185..3aeb89559e75ea2d43b3475767795fea17961cb5 100644 (file)
@@ -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) {
index 0b1614d3d9e68b6f4163681af26f4787ba62df2d..6ecc2ca461079b40b73115f4a81deb6e7f814fd1 100644 (file)
@@ -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) {}
index 40a11e20b4f0aea847e248a7e35a69e152acc118..77e3ddda36fd9566873b9aa60a22b9d42e788785 100644 (file)
@@ -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; }
+  };
+}
index a1543888c39f1a64ca7c5e6243701a3be68ca451..d9331938acb81c397d0ff1d27712604e1b22074a 100644 (file)
@@ -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'