aboutsummaryrefslogtreecommitdiff
path: root/lib/AST/Decl.cpp
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-04-25 13:10:46 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-04-25 13:10:46 +0000
commitf49d9c9b858973eb10717f4b3936a4a4384bd355 (patch)
tree0d3bc8004f607c09959e39cb145de54f9a65c9dc /lib/AST/Decl.cpp
parent65dfa2b31794ff4013cb3f9a8178305b56a3d549 (diff)
Fix a case in linkage computation that should check for single line extern "C".
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180263 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/Decl.cpp')
-rw-r--r--lib/AST/Decl.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index cb375eb4e2..a431c5317e 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -476,6 +476,13 @@ template <typename T> static bool isInExternCContext(T *D) {
return First->getDeclContext()->isExternCContext();
}
+static bool isSingleLineExternC(const Decl &D) {
+ if (const LinkageSpecDecl *SD = dyn_cast<LinkageSpecDecl>(D.getDeclContext()))
+ if (SD->getLanguage() == LinkageSpecDecl::lang_c && !SD->hasBraces())
+ return true;
+ return false;
+}
+
static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D,
LVComputationKind computation) {
assert(D->getDeclContext()->getRedeclContext()->isFileContext() &&
@@ -504,7 +511,8 @@ static LinkageInfo getLVForNamespaceScopeDecl(const NamedDecl *D,
return PrevVar->getLinkageAndVisibility();
if (Var->getStorageClass() != SC_Extern &&
- Var->getStorageClass() != SC_PrivateExtern)
+ Var->getStorageClass() != SC_PrivateExtern &&
+ !isSingleLineExternC(*Var))
return LinkageInfo::internal();
}
@@ -1580,11 +1588,8 @@ VarDecl::DefinitionKind VarDecl::isThisDeclarationADefinition(
// A declaration directly contained in a linkage-specification is treated
// as if it contains the extern specifier for the purpose of determining
// the linkage of the declared name and whether it is a definition.
- const DeclContext *DC = getDeclContext();
- if (const LinkageSpecDecl *SD = dyn_cast<LinkageSpecDecl>(DC)) {
- if (SD->getLanguage() == LinkageSpecDecl::lang_c && !SD->hasBraces())
- return DeclarationOnly;
- }
+ if (isSingleLineExternC(*this))
+ return DeclarationOnly;
// C99 6.9.2p2:
// A declaration of an object that has file scope without an initializer,