r176875 - We already reported an error for
Rafael Espindola
rafael.espindola at gmail.com
Tue Mar 12 09:45:14 PDT 2013
Author: rafael
Date: Tue Mar 12 11:45:13 2013
New Revision: 176875
URL: http://llvm.org/viewvc/llvm-project?rev=176875&view=rev
Log:
We already reported an error for
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.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/SemaCXX/function-redecl.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=176875&r1=176874&r2=176875&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Mar 12 11:45:13 2013
@@ -5004,7 +5004,8 @@ void Sema::CheckShadow(Scope *S, VarDecl
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
Modified: cfe/trunk/test/SemaCXX/function-redecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/function-redecl.cpp?rev=176875&r1=176874&r2=176875&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-redecl.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-redecl.cpp Tue Mar 12 11:45:13 2013
@@ -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'}}
+}
More information about the cfe-commits
mailing list