r182814 - Disallow extern decls of type void in C++ mode

David Majnemer david.majnemer at gmail.com
Tue May 28 17:56:45 PDT 2013


Author: majnemer
Date: Tue May 28 19:56:45 2013
New Revision: 182814

URL: http://llvm.org/viewvc/llvm-project?rev=182814&view=rev
Log:
Disallow extern decls of type void in C++ mode

C++ and C differ with respect to the handling of extern void
declarations. Enforce the C++ behavior in C++ mode.

Modified:
    cfe/trunk/lib/Sema/SemaDecl.cpp
    cfe/trunk/test/SemaCXX/linkage-spec.cpp
    cfe/trunk/test/SemaCXX/qualified-id-lookup.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=182814&r1=182813&r2=182814&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue May 28 19:56:45 2013
@@ -5271,11 +5271,15 @@ void Sema::CheckVariableDeclarationType(
     NewVD->setTypeSourceInfo(FixedTInfo);
   }
 
-  if (T->isVoidType() && NewVD->isThisDeclarationADefinition()) {
-    Diag(NewVD->getLocation(), diag::err_typecheck_decl_incomplete_type)
-      << T;
-    NewVD->setInvalidDecl();
-    return;
+  if (T->isVoidType()) {
+    // C++98 [dcl.stc]p5: The extern specifier can be applied only to the names
+    //                    of objects and functions.
+    if (NewVD->isThisDeclarationADefinition() || getLangOpts().CPlusPlus) {
+      Diag(NewVD->getLocation(), diag::err_typecheck_decl_incomplete_type)
+        << T;
+      NewVD->setInvalidDecl();
+      return;
+    }
   }
 
   if (!NewVD->hasLocalStorage() && NewVD->hasAttr<BlocksAttr>()) {

Modified: cfe/trunk/test/SemaCXX/linkage-spec.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/linkage-spec.cpp?rev=182814&r1=182813&r2=182814&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/linkage-spec.cpp (original)
+++ cfe/trunk/test/SemaCXX/linkage-spec.cpp Tue May 28 19:56:45 2013
@@ -114,3 +114,5 @@ namespace pr14958 {
   }
   int js::ObjectClass;
 }
+
+extern "C" void PR16167; // expected-error {{variable has incomplete type 'void'}}

Modified: cfe/trunk/test/SemaCXX/qualified-id-lookup.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/qualified-id-lookup.cpp?rev=182814&r1=182813&r2=182814&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/qualified-id-lookup.cpp (original)
+++ cfe/trunk/test/SemaCXX/qualified-id-lookup.cpp Tue May 28 19:56:45 2013
@@ -149,6 +149,6 @@ namespace PR6830 {
 }
 
 namespace pr12339 {
-  extern "C" void i;
+  extern "C" void i; // expected-error{{variable has incomplete type 'void'}}
   pr12339::FOO  // expected-error{{no type named 'FOO' in namespace 'pr12339'}}
 }  // expected-error{{expected unqualified-id}}





More information about the cfe-commits mailing list