diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-20 07:22:00 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2017-09-20 07:22:00 +0000 |
commit | 405e2dbf3767586ab06a8506a6f5754aeb5a613d (patch) | |
tree | 7cd5b3ac40b4dd5c57236b1e89445fdec4dc5352 /clang/lib/AST/Decl.cpp | |
parent | 8a65209d0ba5f4553fa1eba89e2e2fcf43c9c01d (diff) | |
download | bcm5719-llvm-405e2dbf3767586ab06a8506a6f5754aeb5a613d.tar.gz bcm5719-llvm-405e2dbf3767586ab06a8506a6f5754aeb5a613d.zip |
Implement C++ [basic.link]p8.
If a function or variable has a type with no linkage (and is not extern "C"),
any use of it requires a definition within the same translation unit; the idea
is that it is not possible to define the entity elsewhere, so any such use is
necessarily an error.
There is an exception, though: some types formally have no linkage but
nonetheless can be referenced from other translation units (for example, this
happens to anonymous structures defined within inline functions). For entities
with those types, we suppress the diagnostic except under -pedantic.
llvm-svn: 313729
Diffstat (limited to 'clang/lib/AST/Decl.cpp')
-rw-r--r-- | clang/lib/AST/Decl.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 0a4c4a4a776..c3e3de1e22b 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -721,8 +721,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, // because of this, but unique-external linkage suits us. if (Context.getLangOpts().CPlusPlus && !isFirstInExternCContext(Var)) { LinkageInfo TypeLV = getLVForType(*Var->getType(), computation); - if (TypeLV.getLinkage() != ExternalLinkage && - TypeLV.getLinkage() != ModuleLinkage) + if (!isExternallyVisible(TypeLV.getLinkage())) return LinkageInfo::uniqueExternal(); if (!LV.isVisibilityExplicit()) LV.mergeVisibility(TypeLV); @@ -772,7 +771,7 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D, QualType TypeAsWritten = Function->getType(); if (TypeSourceInfo *TSI = Function->getTypeSourceInfo()) TypeAsWritten = TSI->getType(); - if (TypeAsWritten->getLinkage() == UniqueExternalLinkage) + if (!isExternallyVisible(TypeAsWritten->getLinkage())) return LinkageInfo::uniqueExternal(); } @@ -909,7 +908,7 @@ LinkageComputer::getLVForClassMember(const NamedDecl *D, const NamedDecl *explicitSpecSuppressor = nullptr; if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) { - // If the type of the function uses a type with unique-external + // If the type of the function uses a type that has non-externally-visible // linkage, it's not legally usable from outside this translation unit. // But only look at the type-as-written. If this function has an // auto-deduced return type, we can't compute the linkage of that type @@ -922,7 +921,7 @@ LinkageComputer::getLVForClassMember(const NamedDecl *D, QualType TypeAsWritten = MD->getType(); if (TypeSourceInfo *TSI = MD->getTypeSourceInfo()) TypeAsWritten = TSI->getType(); - if (TypeAsWritten->getLinkage() == UniqueExternalLinkage) + if (!isExternallyVisible(TypeAsWritten->getLinkage())) return LinkageInfo::uniqueExternal(); } // If this is a method template specialization, use the linkage for @@ -1119,6 +1118,9 @@ LinkageInfo LinkageComputer::getLVForClosure(const DeclContext *DC, Decl *ContextDecl, LVComputationKind computation) { // This lambda has its linkage/visibility determined by its owner. + // FIXME: This is wrong. A lambda never formally has linkage; if this + // calculation determines the lambda has external linkage, it should be + // downgraded to VisibleNoLinkage. if (ContextDecl) { if (isa<ParmVarDecl>(ContextDecl)) DC = ContextDecl->getDeclContext()->getRedeclContext(); |