]> granicus.if.org Git - clang/commitdiff
We already reported an error for
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 12 Mar 2013 16:45:13 +0000 (16:45 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 12 Mar 2013 16:45:13 +0000 (16:45 +0000)
extern "C" {
  void test5_f() {
    extern int test5_b;
  }
}
static float test5_b;

This patch makes us report one for

extern "C" {
  void test6_f() {
    extern int test6_b;
  }
}
extern "C" {
  static float test6_b;
}

Not because we think the declaration would be extern C, but because of the rule:

An entity with C language linkage shall not be declared with the same name as an entity in global scope...

We were just not looking past the extern "C" to see if the decl was in global
scope.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@176875 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/SemaCXX/function-redecl.cpp

index 252f94dc226de86ba9b6b76623b43cb1e052b65a..659d9638f474f318ef05ac5f0a51e6b04bcf4a7b 100644 (file)
@@ -5004,7 +5004,8 @@ void Sema::CheckShadow(Scope *S, VarDecl *D) {
 
 template<typename T>
 static bool mayConflictWithNonVisibleExternC(const T *ND) {
-  return ND->isExternC() || ND->getDeclContext()->isTranslationUnit();
+  return ND->isExternC() ||
+    ND->getDeclContext()->getRedeclContext()->isTranslationUnit();
 }
 
 /// \brief Perform semantic checking on a newly-created variable
index 7bf44b1c36d986a31e017565b3e32c5e9c4f26d6..8cbda82c0b1b5019e196a8040efe6137edfed35d 100644 (file)
@@ -145,3 +145,19 @@ namespace test4 {
     float b; // expected-error {{redefinition of 'b' with a different type: 'float' vs 'int'}}
   }
 }
+
+extern "C" {
+  void test5_f() {
+    extern int test5_b; // expected-note {{previous definition is here}}
+  }
+}
+static float test5_b; // expected-error {{redefinition of 'test5_b' with a different type: 'float' vs 'int'}}
+
+extern "C" {
+  void test6_f() {
+    extern int test6_b; // expected-note {{previous definition is here}}
+  }
+}
+extern "C" {
+  static float test6_b; // expected-error {{redefinition of 'test6_b' with a different type: 'float' vs 'int'}}
+}