[cfe-commits] r46102 - in /cfe/trunk: AST/Type.cpp include/clang/AST/Decl.h test/Sema/enum.c

Steve Naroff snaroff at apple.com
Wed Jan 16 15:54:22 PST 2008


Author: snaroff
Date: Wed Jan 16 17:54:22 2008
New Revision: 46102

URL: http://llvm.org/viewvc/llvm-project?rev=46102&view=rev
Log:

Type::isArithmeticType(): disallow incomplete enum decls.

Bug submitted by Eli.

Modified:
    cfe/trunk/AST/Type.cpp
    cfe/trunk/include/clang/AST/Decl.h
    cfe/trunk/test/Sema/enum.c

Modified: cfe/trunk/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/AST/Type.cpp?rev=46102&r1=46101&r2=46102&view=diff

==============================================================================
--- cfe/trunk/AST/Type.cpp (original)
+++ cfe/trunk/AST/Type.cpp Wed Jan 16 17:54:22 2008
@@ -444,8 +444,11 @@
   if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
     return BT->getKind() != BuiltinType::Void;
   if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
-    if (TT->getDecl()->getKind() == Decl::Enum)
-      return true;
+    if (const EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl()))
+      // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
+      // If a body isn't seen by the time we get here, we exclude it from
+      // being allowed in arithmetic expressions.
+      return ED->isDefinition();
   return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
 }
 

Modified: cfe/trunk/include/clang/AST/Decl.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=46102&r1=46101&r2=46102&view=diff

==============================================================================
--- cfe/trunk/include/clang/AST/Decl.h (original)
+++ cfe/trunk/include/clang/AST/Decl.h Wed Jan 16 17:54:22 2008
@@ -663,6 +663,7 @@
   EnumDecl(SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
     : TagDecl(Enum, L, Id, PrevDecl) {
     ElementList = 0;
+	IntegerType = QualType();
   }
   
   /// defineElements - When created, EnumDecl correspond to a forward declared

Modified: cfe/trunk/test/Sema/enum.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/enum.c?rev=46102&r1=46101&r2=46102&view=diff

==============================================================================
--- cfe/trunk/test/Sema/enum.c (original)
+++ cfe/trunk/test/Sema/enum.c Wed Jan 16 17:54:22 2008
@@ -22,3 +22,9 @@
   return sizeof(enum e) ;
 }
 
+enum gccForwardEnumExtension ve; // expected-warning {{ISO C forbids forward references to 'enum' types}}
+
+int test2(int i)
+{
+  ve + i; // expected-error{{invalid operands to binary expression ('enum gccForwardEnumExtension' and 'int')}}
+}





More information about the cfe-commits mailing list