[cfe-commits] r39366 - in /cfe/cfe/trunk: AST/SemaType.cpp Sema/SemaType.cpp include/clang/Basic/DiagnosticKinds.def

Steve Naroff snaroff at apple.com
Wed Jul 11 09:43:39 PDT 2007


Author: snaroff
Date: Wed Jul 11 11:43:39 2007
New Revision: 39366

URL: http://llvm.org/viewvc/llvm-project?rev=39366&view=rev
Log:
Bug #:
Submitted by:
Reviewed by:
Finish up fixes to Sema::GetTypeForDeclarator(). The typechecking should
now conform to the standard.

Modified:
    cfe/cfe/trunk/AST/SemaType.cpp
    cfe/cfe/trunk/Sema/SemaType.cpp
    cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def

Modified: cfe/cfe/trunk/AST/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/AST/SemaType.cpp?rev=39366&r1=39365&r2=39366&view=diff

==============================================================================
--- cfe/cfe/trunk/AST/SemaType.cpp (original)
+++ cfe/cfe/trunk/AST/SemaType.cpp Wed Jul 11 11:43:39 2007
@@ -133,23 +133,26 @@
       
       Type *CanonicalT = T->getCanonicalType();
       
-      // If the element type is a struct or union that contains a variadic
-      // array, reject it: C99 6.7.2.1p2.
-      if (RecordType *EltTy = dyn_cast<RecordType>(CanonicalT)) {
+      // C99 6.7.5.2p1: If the element type is an incomplete or function type, 
+      // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]())
+      if (T->isIncompleteType()) { 
+        Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_incomplete_type,
+             D.getIdentifier()->getName());
+        return TypeRef();
+      } else if (isa<FunctionType>(CanonicalT)) {
+        Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
+             D.getIdentifier()->getName());
+        return TypeRef();
+      } else if (RecordType *EltTy = dyn_cast<RecordType>(CanonicalT)) {
+        // If the element type is a struct or union that contains a variadic
+        // array, reject it: C99 6.7.2.1p2.
         if (EltTy->getDecl()->hasFlexibleArrayMember()) {
           std::string Name;
           T->getAsString(Name);
           Diag(DeclType.Loc, diag::err_flexible_array_in_array, Name);
           return TypeRef();
         }
-      } else if (isa<FunctionType>(CanonicalT)) {// reject "void aryOfFunc[3]()"
-        Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
-             D.getIdentifier()->getName());
-      } else if (CanonicalT->isVoidType()) { // reject "void aryOfVoids[3]"
-        Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_voids,
-             D.getIdentifier()->getName());
       }
-      
       T = Context.getArrayType(T, ASM, ATI.TypeQuals, 
                                static_cast<Expr *>(ATI.NumElts));
       break;

Modified: cfe/cfe/trunk/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/Sema/SemaType.cpp?rev=39366&r1=39365&r2=39366&view=diff

==============================================================================
--- cfe/cfe/trunk/Sema/SemaType.cpp (original)
+++ cfe/cfe/trunk/Sema/SemaType.cpp Wed Jul 11 11:43:39 2007
@@ -133,23 +133,26 @@
       
       Type *CanonicalT = T->getCanonicalType();
       
-      // If the element type is a struct or union that contains a variadic
-      // array, reject it: C99 6.7.2.1p2.
-      if (RecordType *EltTy = dyn_cast<RecordType>(CanonicalT)) {
+      // C99 6.7.5.2p1: If the element type is an incomplete or function type, 
+      // reject it (e.g. void ary[7], struct foo ary[7], void ary[7]())
+      if (T->isIncompleteType()) { 
+        Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_incomplete_type,
+             D.getIdentifier()->getName());
+        return TypeRef();
+      } else if (isa<FunctionType>(CanonicalT)) {
+        Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
+             D.getIdentifier()->getName());
+        return TypeRef();
+      } else if (RecordType *EltTy = dyn_cast<RecordType>(CanonicalT)) {
+        // If the element type is a struct or union that contains a variadic
+        // array, reject it: C99 6.7.2.1p2.
         if (EltTy->getDecl()->hasFlexibleArrayMember()) {
           std::string Name;
           T->getAsString(Name);
           Diag(DeclType.Loc, diag::err_flexible_array_in_array, Name);
           return TypeRef();
         }
-      } else if (isa<FunctionType>(CanonicalT)) {// reject "void aryOfFunc[3]()"
-        Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_functions,
-             D.getIdentifier()->getName());
-      } else if (CanonicalT->isVoidType()) { // reject "void aryOfVoids[3]"
-        Diag(D.getIdentifierLoc(), diag::err_illegal_decl_array_of_voids,
-             D.getIdentifier()->getName());
       }
-      
       T = Context.getArrayType(T, ASM, ATI.TypeQuals, 
                                static_cast<Expr *>(ATI.NumElts));
       break;

Modified: cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def
URL: http://llvm.org/viewvc/llvm-project/cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def?rev=39366&r1=39365&r2=39366&view=diff

==============================================================================
--- cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def (original)
+++ cfe/cfe/trunk/include/clang/Basic/DiagnosticKinds.def Wed Jul 11 11:43:39 2007
@@ -464,8 +464,8 @@
      "'%s' may not be used as an array element due to flexible array member")
 DIAG(err_illegal_decl_array_of_functions, ERROR,
      "'%s' declared as array of functions")
-DIAG(err_illegal_decl_array_of_voids, ERROR,
-     "'%s' declared as array of voids")
+DIAG(err_illegal_decl_array_incomplete_type, ERROR,
+     "array type for '%s' has incomplete element type")
      
 // Expressions.
 DIAG(ext_sizeof_function_type, EXTENSION,





More information about the cfe-commits mailing list