From: Fariborz Jahanian Date: Mon, 29 Nov 2010 23:18:09 +0000 (+0000) Subject: Incomplete enum types not to be treated as integer type X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bbd340717422bf011d56cd0164d2576601368111;p=clang Incomplete enum types not to be treated as integer type when checking for integer signed/unsigned-ness. PR8694, // rdar://8707031 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@120345 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 3c9561cd44..56cd4dddb5 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -489,8 +489,12 @@ bool Type::isSignedIntegerType() const { BT->getKind() <= BuiltinType::Int128; } - if (const EnumType *ET = dyn_cast(CanonicalType)) - return ET->getDecl()->getIntegerType()->isSignedIntegerType(); + if (const EnumType *ET = dyn_cast(CanonicalType)) { + // Incomplete enum types are not treated as integer types. + // FIXME: In C++, enum types are never integer types. + if (ET->getDecl()->isComplete()) + return ET->getDecl()->getIntegerType()->isSignedIntegerType(); + } return false; } @@ -511,8 +515,12 @@ bool Type::isUnsignedIntegerType() const { BT->getKind() <= BuiltinType::UInt128; } - if (const EnumType *ET = dyn_cast(CanonicalType)) - return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); + if (const EnumType *ET = dyn_cast(CanonicalType)) { + // Incomplete enum types are not treated as integer types. + // FIXME: In C++, enum types are never integer types. + if (ET->getDecl()->isComplete()) + return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); + } return false; } diff --git a/test/Sema/enum.c b/test/Sema/enum.c index d83b06f56b..a95efb035d 100644 --- a/test/Sema/enum.c +++ b/test/Sema/enum.c @@ -104,3 +104,16 @@ void PR7911F() { } char test5[__has_feature(enumerator_attributes) ? 1 : -1]; + +// PR8694 +// rdar://8707031 +void PR8694(int* e) // expected-note {{passing argument to parameter 'e' here}} +{ +} + +void crash(enum E* e) // expected-warning {{declaration of 'enum E' will not be visible outside of this function}} \ + // expected-warning {{ISO C forbids forward references to 'enum' types}} +{ + PR8694(e); // expected-warning {{incompatible pointer types passing 'enum E *' to parameter of type 'int *'}} +} +