From: Douglas Gregor Date: Thu, 5 May 2011 16:13:52 +0000 (+0000) Subject: Scoped enumerations should not be treated as integer types (in the C X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b6adf2c889bb17c1be44e6c8e67e3b2762e9cecc;p=clang Scoped enumerations should not be treated as integer types (in the C sense). Fixes by eliminating an inconsistency between C++ overloading (which handled scoped enumerations correctly) and C binary operator type-checking (which didn't). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130924 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp index 9eb497bea6..ed22235593 100644 --- a/lib/AST/Type.cpp +++ b/lib/AST/Type.cpp @@ -517,7 +517,7 @@ bool Type::isIntegerType() const { 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. - return ET->getDecl()->isComplete(); + return ET->getDecl()->isComplete() && !ET->getDecl()->isScoped(); return false; } @@ -641,7 +641,7 @@ bool Type::isSignedIntegerType() const { 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()) + if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) return ET->getDecl()->getIntegerType()->isSignedIntegerType(); } @@ -667,7 +667,7 @@ bool Type::isUnsignedIntegerType() const { 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()) + if (ET->getDecl()->isComplete() && !ET->getDecl()->isScoped()) return ET->getDecl()->getIntegerType()->isUnsignedIntegerType(); } diff --git a/test/SemaCXX/enum-scoped.cpp b/test/SemaCXX/enum-scoped.cpp index 8c4bfe72d3..fc871cf379 100644 --- a/test/SemaCXX/enum-scoped.cpp +++ b/test/SemaCXX/enum-scoped.cpp @@ -109,3 +109,13 @@ void PR9333() { scoped_enum e = scoped_enum::yes; if (e == scoped_enum::no) { } } + +// +namespace rdar9366066 { + enum class X : unsigned { value }; + + void f(X x) { + x % X::value; // expected-error{{invalid operands to binary expression ('rdar9366066::X' and 'rdar9366066::X')}} + x % 8; // expected-error{{invalid operands to binary expression ('rdar9366066::X' and 'int')}} + } +}