From: Richard Smith Date: Sun, 23 Mar 2014 19:45:26 +0000 (+0000) Subject: When we inject a declaration into a namespace, add the primary DeclContext to X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9d5cd13e24d080ffb2d0af53cf06efbc1bdd5b2e;p=clang When we inject a declaration into a namespace, add the primary DeclContext to 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 --- diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 3aeb89559e..4474328ec3 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -185,8 +185,9 @@ void ASTDeclWriter::VisitDecl(Decl *D) { // function with a local extern declaration, for instance. if (D->isOutOfLine()) { auto *NS = dyn_cast(D->getDeclContext()->getRedeclContext()); + // FIXME: Also update surrounding inline namespaces. if (NS && NS->isFromASTFile()) - Writer.AddUpdatedDeclContext(NS); + Writer.AddUpdatedDeclContext(NS->getPrimaryContext()); } } diff --git a/test/Modules/Inputs/cxx-templates-b.h b/test/Modules/Inputs/cxx-templates-b.h index 6cd83faf1a..a682855302 100644 --- a/test/Modules/Inputs/cxx-templates-b.h +++ b/test/Modules/Inputs/cxx-templates-b.h @@ -66,4 +66,5 @@ template void UseDefinedInBImplIndirectly(T &v) { void TriggerInstantiation() { UseDefinedInBImpl(); + Std::f(); } diff --git a/test/Modules/Inputs/cxx-templates-common.h b/test/Modules/Inputs/cxx-templates-common.h index 77e3ddda36..9b46539a99 100644 --- a/test/Modules/Inputs/cxx-templates-common.h +++ b/test/Modules/Inputs/cxx-templates-common.h @@ -15,3 +15,9 @@ namespace Std { friend bool operator!=(const WithFriend &A, const WithFriend &B) { return false; } }; } + +namespace Std { + template void f() { + extern T g(); + } +} diff --git a/test/Modules/cxx-templates.cpp b/test/Modules/cxx-templates.cpp index d9331938ac..7b4e57ce1a 100644 --- a/test/Modules/cxx-templates.cpp +++ b/test/Modules/cxx-templates.cpp @@ -121,6 +121,11 @@ bool testFriendInClassTemplate(Std::WithFriend 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'