diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-10-09 23:42:09 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-10-09 23:42:09 +0000 |
commit | b87720b77aee65e30a6181e239cbf708f4d29259 (patch) | |
tree | 5c9c3dc2f06f6e6a741f4833e2458858a1f57ad7 /clang/lib/AST/Decl.cpp | |
parent | 8b53f7ca6daa21ea4510c0d2b35bee7edade6b0e (diff) | |
download | bcm5719-llvm-b87720b77aee65e30a6181e239cbf708f4d29259.tar.gz bcm5719-llvm-b87720b77aee65e30a6181e239cbf708f4d29259.zip |
[Modules TS] Module ownership semantics for redeclarations.
When declaring an entity in the "purview" of a module, it's never a
redeclaration of an entity in the purview of a default module or in no module
("in the global module"). Don't consider those other declarations as possible
redeclaration targets if they're not visible, and reject any cases where we
pick a prior visible declaration that violates this rule.
llvm-svn: 315251
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 6e5f638bd55..cdd89d20e6b 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -515,6 +515,7 @@ static bool isSingleLineLanguageLinkage(const Decl &D) { } static bool isExportedFromModuleIntefaceUnit(const NamedDecl *D) { + // FIXME: Handle isModulePrivate. switch (D->getModuleOwnershipKind()) { case Decl::ModuleOwnershipKind::Unowned: case Decl::ModuleOwnershipKind::ModulePrivate: @@ -546,7 +547,8 @@ static LinkageInfo getExternalLinkageFor(const NamedDecl *D) { // declaration has module linkage. if (auto *M = D->getOwningModule()) if (M->Kind == Module::ModuleInterfaceUnit) - if (!isExportedFromModuleIntefaceUnit(D)) + if (!isExportedFromModuleIntefaceUnit( + cast<NamedDecl>(D->getCanonicalDecl()))) return LinkageInfo(ModuleLinkage, DefaultVisibility, false); return LinkageInfo::external(); @@ -1393,7 +1395,7 @@ LinkageInfo LinkageComputer::getDeclLinkageAndVisibility(const NamedDecl *D) { : NamedDecl::VisibilityForValue)); } -Module *NamedDecl::getOwningModuleForLinkage() const { +Module *Decl::getOwningModuleForLinkage() const { Module *M = getOwningModule(); if (!M) return nullptr; @@ -1411,7 +1413,15 @@ Module *NamedDecl::getOwningModuleForLinkage() const { // for linkage purposes. But internal linkage declarations in the global // module fragment of a particular module are owned by that module for // linkage purposes. - return hasExternalFormalLinkage() ? nullptr : M->Parent; + bool InternalLinkage; + if (auto *ND = dyn_cast<NamedDecl>(this)) + InternalLinkage = !ND->hasExternalFormalLinkage(); + else { + auto *NSD = dyn_cast<NamespaceDecl>(this); + InternalLinkage = (NSD && NSD->isAnonymousNamespace()) || + isInAnonymousNamespace(); + } + return InternalLinkage ? M->Parent : nullptr; } llvm_unreachable("unknown module kind"); |