r180263 - Fix a case in linkage computation that should check for single line extern "C".
Rafael Espindola
rafael.espindola at gmail.com
Thu Apr 25 06:10:46 PDT 2013
Author: rafael
Date: Thu Apr 25 08:10:46 2013
New Revision: 180263
URL: http://llvm.org/viewvc/llvm-project?rev=180263&view=rev
Log:
Fix a case in linkage computation that should check for single line extern "C".
Modified:
cfe/trunk/lib/AST/Decl.cpp
cfe/trunk/test/SemaCXX/undefined-internal.cpp
Modified: cfe/trunk/lib/AST/Decl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=180263&r1=180262&r2=180263&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Decl.cpp (original)
+++ cfe/trunk/lib/AST/Decl.cpp Thu Apr 25 08:10:46 2013
@@ -476,6 +476,13 @@ template <typename T> static bool isInEx
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 getLVForNamespaceScop
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::isThisD
// 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,
Modified: cfe/trunk/test/SemaCXX/undefined-internal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/undefined-internal.cpp?rev=180263&r1=180262&r2=180263&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/undefined-internal.cpp (original)
+++ cfe/trunk/test/SemaCXX/undefined-internal.cpp Thu Apr 25 08:10:46 2013
@@ -323,3 +323,10 @@ namespace test13 {
}
}
+namespace test14 {
+ extern "C" const int foo;
+
+ int f() {
+ return foo;
+ }
+}
More information about the cfe-commits
mailing list