]> granicus.if.org Git - clang/commitdiff
Implement comparison of C++0x scoped enumeration types. Fixes PR9333.
authorDouglas Gregor <dgregor@apple.com>
Tue, 1 Mar 2011 17:16:20 +0000 (17:16 +0000)
committerDouglas Gregor <dgregor@apple.com>
Tue, 1 Mar 2011 17:16:20 +0000 (17:16 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126752 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/enum-scoped.cpp

index ae0ed3e4f168439e291dcaf2b3db43434a60b7ca..321e96f1e75f3bd71e729ec2d0d9b0795cee9283 100644 (file)
@@ -7024,6 +7024,12 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
       ImpCastExprToType(rex, T, CK_BitCast);
       return ResultTy;
     }
+
+    // Handle scoped enumeration types specifically, since they don't promote
+    // to integers.
+    if (lex->getType()->isEnumeralType() &&
+        Context.hasSameUnqualifiedType(lex->getType(), rex->getType()))
+      return ResultTy;
   }
 
   // Handle block pointer types.
@@ -7123,6 +7129,7 @@ QualType Sema::CheckCompareOperands(Expr *&lex, Expr *&rex, SourceLocation Loc,
     ImpCastExprToType(lex, rType, CK_NullToPointer);
     return ResultTy;
   }
+
   return InvalidOperands(Loc, lex, rex);
 }
 
index cf579e180f6964d1103f0b19141ab0b2ac6ce96f..8c4bfe72d3e2c4cd19da91d4da24ab5c8e9c1a1a 100644 (file)
@@ -103,3 +103,9 @@ enum : long {
 
 enum : long x; // expected-error{{unnamed enumeration must be a definition}} \
 // expected-warning{{declaration does not declare anything}}
+
+void PR9333() {
+  enum class scoped_enum { yes, no, maybe };
+  scoped_enum e = scoped_enum::yes;
+  if (e == scoped_enum::no) { }
+}