r176867 - Error if an extern C declaration matches a previous hidden extern C declaration.

Rafael Espindola rafael.espindola at gmail.com
Tue Mar 12 08:13:57 PDT 2013


Author: rafael
Date: Tue Mar 12 10:13:56 2013
New Revision: 176867

URL: http://llvm.org/viewvc/llvm-project?rev=176867&view=rev
Log:
Error if an extern C declaration matches a previous hidden extern C declaration.

Without this patch we produce an error for

extern "C" {
  void f() {
    extern int b;
  }
}
extern "C" {
  extern float b;
}

but not for

extern "C" {
  void f() {
    extern int b;
  }
}
extern "C" {
  float b;
}

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=176867&r1=176866&r2=176867&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Mar 12 10:13:56 2013
@@ -5004,10 +5004,7 @@ void Sema::CheckShadow(Scope *S, VarDecl
 
 template<typename T>
 static bool mayConflictWithNonVisibleExternC(const T *ND) {
-  VarDecl::StorageClass SC = ND->getStorageClass();
-  if (ND->isExternC() && (SC == SC_Extern || SC == SC_PrivateExtern))
-    return true;
-  return ND->getDeclContext()->isTranslationUnit();
+  return ND->isExternC() || ND->getDeclContext()->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=176867&r1=176866&r2=176867&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/function-redecl.cpp (original)
+++ cfe/trunk/test/SemaCXX/function-redecl.cpp Tue Mar 12 10:13:56 2013
@@ -134,3 +134,14 @@ namespace test3 {
   }
 }
 float test3_x; // expected-error {{redefinition of 'test3_x' with a different type: 'float' vs 'int'}}
+
+namespace test4 {
+  extern "C" {
+    void f() {
+      extern int b; // expected-note {{previous definition is here}}
+    }
+  }
+  extern "C" {
+    float b; // expected-error {{redefinition of 'b' with a different type: 'float' vs 'int'}}
+  }
+}





More information about the cfe-commits mailing list