From f8ef031677dc7629b1dfcb7eb48c900c62a0a5e2 Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Sun, 23 Mar 2014 20:41:56 +0000 Subject: [PATCH] If a name is injected into an imported inline namespace without reopening that namespace, we need to update both the visible names of that namespace and of its enclosing namespace set. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@204570 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Serialization/ASTWriterDecl.cpp | 11 ++++++++--- test/Modules/Inputs/cxx-inline-namespace.h | 6 ++++++ test/Modules/Inputs/module.map | 4 ++++ test/Modules/cxx-inline-namespace.cpp | 3 +++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/Serialization/ASTWriterDecl.cpp b/lib/Serialization/ASTWriterDecl.cpp index 4474328ec3..f0b0312834 100644 --- a/lib/Serialization/ASTWriterDecl.cpp +++ b/lib/Serialization/ASTWriterDecl.cpp @@ -184,10 +184,15 @@ void ASTDeclWriter::VisitDecl(Decl *D) { // 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()); - // FIXME: Also update surrounding inline namespaces. - if (NS && NS->isFromASTFile()) + auto *DC = D->getDeclContext(); + while (auto *NS = dyn_cast(DC->getRedeclContext())) { + if (!NS->isFromASTFile()) + break; Writer.AddUpdatedDeclContext(NS->getPrimaryContext()); + if (!NS->isInlineNamespace()) + break; + DC = NS->getParent(); + } } } diff --git a/test/Modules/Inputs/cxx-inline-namespace.h b/test/Modules/Inputs/cxx-inline-namespace.h index 2525ad3569..4feb850180 100644 --- a/test/Modules/Inputs/cxx-inline-namespace.h +++ b/test/Modules/Inputs/cxx-inline-namespace.h @@ -9,3 +9,9 @@ namespace std { typedef int size_t; } } + +namespace X { + inline namespace Y { + struct Z; + } +} diff --git a/test/Modules/Inputs/module.map b/test/Modules/Inputs/module.map index 9f0fc0a29d..d6effcf0ad 100644 --- a/test/Modules/Inputs/module.map +++ b/test/Modules/Inputs/module.map @@ -198,6 +198,10 @@ module cxx_inline_namespace { header "cxx-inline-namespace.h" } +module cxx_inline_namespace_b { + header "cxx-inline-namespace-b.h" +} + module cxx_linkage_cache { header "cxx-linkage-cache.h" } diff --git a/test/Modules/cxx-inline-namespace.cpp b/test/Modules/cxx-inline-namespace.cpp index 5b967901b3..f67d43b684 100644 --- a/test/Modules/cxx-inline-namespace.cpp +++ b/test/Modules/cxx-inline-namespace.cpp @@ -2,5 +2,8 @@ // RUN: %clang_cc1 -x objective-c++ -fmodules -fmodules-cache-path=%t -I %S/Inputs %s -verify -std=c++11 @import cxx_inline_namespace; +@import cxx_inline_namespace_b; T x; // expected-error {{unknown type name 'T'}} + +X::Elaborated *p; -- 2.40.0