File tree Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Expand file tree Collapse file tree 3 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -444,8 +444,11 @@ bool Type::isArithmeticType() const {
444
444
if (const BuiltinType *BT = dyn_cast<BuiltinType>(CanonicalType))
445
445
return BT->getKind () != BuiltinType::Void;
446
446
if (const TagType *TT = dyn_cast<TagType>(CanonicalType))
447
- if (TT->getDecl ()->getKind () == Decl::Enum)
448
- return true ;
447
+ if (const EnumDecl *ED = dyn_cast<EnumDecl>(TT->getDecl ()))
448
+ // GCC allows forward declaration of enum types (forbid by C99 6.7.2.3p2).
449
+ // If a body isn't seen by the time we get here, we exclude it from
450
+ // being allowed in arithmetic expressions.
451
+ return ED->isDefinition ();
449
452
return isa<ComplexType>(CanonicalType) || isa<VectorType>(CanonicalType);
450
453
}
451
454
Original file line number Diff line number Diff line change @@ -663,6 +663,7 @@ class EnumDecl : public TagDecl {
663
663
EnumDecl (SourceLocation L, IdentifierInfo *Id, ScopedDecl *PrevDecl)
664
664
: TagDecl(Enum, L, Id, PrevDecl) {
665
665
ElementList = 0 ;
666
+ IntegerType = QualType ();
666
667
}
667
668
668
669
// / defineElements - When created, EnumDecl correspond to a forward declared
Original file line number Diff line number Diff line change @@ -22,3 +22,9 @@ int test() {
22
22
return sizeof (enum e ) ;
23
23
}
24
24
25
+ enum gccForwardEnumExtension ve ; // expected-warning {{ISO C forbids forward references to 'enum' types}}
26
+
27
+ int test2 (int i )
28
+ {
29
+ ve + i ; // expected-error{{invalid operands to binary expression ('enum gccForwardEnumExtension' and 'int')}}
30
+ }
You can’t perform that action at this time.
0 commit comments