diff options
author | Steve Naroff <snaroff@apple.com> | 2008-01-16 23:54:22 +0000 |
---|---|---|
committer | Steve Naroff <snaroff@apple.com> | 2008-01-16 23:54:22 +0000 |
commit | 8a0abea99921d6082f56489b6044de9f0cd01fbb (patch) | |
tree | 326561da6b671b6457b4aefed51dc96c47f058dc | |
parent | 506e507508b69ef8350c2de8e6fa66a463f292a0 (diff) | |
download | llvm-8a0abea99921d6082f56489b6044de9f0cd01fbb.tar.gz |
Type::isArithmeticType(): disallow incomplete enum decls.
Bug submitted by Eli.
llvm-svn: 46102
-rw-r--r-- | clang/AST/Type.cpp | 7 | ||||
-rw-r--r-- | clang/include/clang/AST/Decl.h | 1 | ||||
-rw-r--r-- | clang/test/Sema/enum.c | 6 |
3 files changed, 12 insertions, 2 deletions
diff --git a/clang/AST/Type.cpp b/clang/AST/Type.cpp index 78e0dbbb2719..e59569d2d64b 100644 --- a/clang/AST/Type.cpp +++ b/clang/AST/Type.cpp @@ -444,8 +444,11 @@ bool Type::isArithmeticType() const { 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); } diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 40af7bada0bd..0bd250d99b67 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -663,6 +663,7 @@ public: 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 diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c index 79a92c8f2d49..169c394c50fa 100644 --- a/clang/test/Sema/enum.c +++ b/clang/test/Sema/enum.c @@ -22,3 +22,9 @@ int test() { 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')}} +} |