]> granicus.if.org Git - clang/commitdiff
When we inject a declaration into a namespace, add the primary DeclContext to
authorRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 23 Mar 2014 19:45:26 +0000 (19:45 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Sun, 23 Mar 2014 19:45:26 +0000 (19:45 +0000)
the update set rather than the current DeclContext. Add test for the local
extern case too.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204568 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Serialization/ASTWriterDecl.cpp
test/Modules/Inputs/cxx-templates-b.h
test/Modules/Inputs/cxx-templates-common.h
test/Modules/cxx-templates.cpp

index 3aeb89559e75ea2d43b3475767795fea17961cb5..4474328ec3b3dfb1754a555c5be9edfdf8bb26c3 100644 (file)
@@ -185,8 +185,9 @@ void ASTDeclWriter::VisitDecl(Decl *D) {
   // function with a local extern declaration, for instance.
   if (D->isOutOfLine()) {
     auto *NS = dyn_cast<NamespaceDecl>(D->getDeclContext()->getRedeclContext());
+    // FIXME: Also update surrounding inline namespaces.
     if (NS && NS->isFromASTFile())
-      Writer.AddUpdatedDeclContext(NS);
+      Writer.AddUpdatedDeclContext(NS->getPrimaryContext());
   }
 }
 
index 6cd83faf1a1bdae1e7605761b56cbcf920cfbb2f..a682855302774e5bb642be0b302e730b8be061e5 100644 (file)
@@ -66,4 +66,5 @@ template<typename T> void UseDefinedInBImplIndirectly(T &v) {
 
 void TriggerInstantiation() {
   UseDefinedInBImpl<void>();
+  Std::f<int>();
 }
index 77e3ddda36fd9566873b9aa60a22b9d42e788785..9b46539a99415613d1d862cd768b9b505ad791c8 100644 (file)
@@ -15,3 +15,9 @@ namespace Std {
     friend bool operator!=(const WithFriend &A, const WithFriend &B) { return false; }
   };
 }
+
+namespace Std {
+  template<typename T> void f() {
+    extern T g();
+  }
+}
index d9331938acb81c397d0ff1d27712604e1b22074a..7b4e57ce1acaf58e1056aac26351f1bcb469454b 100644 (file)
@@ -121,6 +121,11 @@ bool testFriendInClassTemplate(Std::WithFriend<int> wfi) {
   return wfi != wfi;
 }
 
+namespace Std {
+  void g(); // expected-error {{functions that differ only in their return type cannot be overloaded}}
+  // expected-note@cxx-templates-common.h:21 {{previous}}
+}
+
 // CHECK-GLOBAL:      DeclarationName 'f'
 // CHECK-GLOBAL-NEXT: |-FunctionTemplate {{.*}} 'f'
 // CHECK-GLOBAL-NEXT: `-FunctionTemplate {{.*}} 'f'