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

Bug submitted by Eli.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46102 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Steve Naroff 2008-01-16 23:54:22 +00:00
Родитель e3d7c24f28
Коммит 67c49e892b
3 изменённых файлов: 12 добавлений и 2 удалений

Просмотреть файл

@ -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);
}

Просмотреть файл

@ -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

Просмотреть файл

@ -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')}}
}