]> granicus.if.org Git - clang/commitdiff
Fix a case in linkage computation that should check for single line extern "C".
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 25 Apr 2013 13:10:46 +0000 (13:10 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 25 Apr 2013 13:10:46 +0000 (13:10 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@180263 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Decl.cpp
test/SemaCXX/undefined-internal.cpp

index cb375eb4e26a2ff2452764855f8cae04d56d0135..a431c5317e05e3f2073b5ee6a7de93998e694cd7 100644 (file)
@@ -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,
index 839fdafb34188d86f8fe29c373282182b21f8367..1b76a86dcb5ac37691232278404ad5c5b12ee4d2 100644 (file)
@@ -323,3 +323,10 @@ namespace test13 {
   }
 }
 
+namespace test14 {
+  extern "C" const int foo;
+
+  int f() {
+    return foo;
+  }
+}