[cfe-commits] r130924 - in /cfe/trunk: lib/AST/Type.cpp test/SemaCXX/enum-scoped.cpp
Douglas Gregor
dgregor at apple.com
Thu May 5 09:13:52 PDT 2011
Author: dgregor
Date: Thu May 5 11:13:52 2011
New Revision: 130924
URL: http://llvm.org/viewvc/llvm-project?rev=130924&view=rev
Log:
Scoped enumerations should not be treated as integer types (in the C
sense). Fixes <rdar://problem/9366066> by eliminating an inconsistency
between C++ overloading (which handled scoped enumerations correctly)
and C binary operator type-checking (which didn't).
Modified:
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/test/SemaCXX/enum-scoped.cpp
Modified: cfe/trunk/lib/AST/Type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=130924&r1=130923&r2=130924&view=diff
==============================================================================
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Thu May 5 11:13:52 2011
@@ -517,7 +517,7 @@
if (const EnumType *ET = dyn_cast<EnumType>(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 @@
if (const EnumType *ET = dyn_cast<EnumType>(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 @@
if (const EnumType *ET = dyn_cast<EnumType>(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();
}
Modified: cfe/trunk/test/SemaCXX/enum-scoped.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum-scoped.cpp?rev=130924&r1=130923&r2=130924&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enum-scoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum-scoped.cpp Thu May 5 11:13:52 2011
@@ -109,3 +109,13 @@
scoped_enum e = scoped_enum::yes;
if (e == scoped_enum::no) { }
}
+
+// <rdar://problem/9366066>
+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')}}
+ }
+}
More information about the cfe-commits
mailing list