Implement comparison of C++0x scoped enumeration types. Fixes PR9333.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@126752 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index ae0ed3e..321e96f 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -7024,6 +7024,12 @@
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 @@
ImpCastExprToType(lex, rType, CK_NullToPointer);
return ResultTy;
}
+
return InvalidOperands(Loc, lex, rex);
}
diff --git a/test/SemaCXX/enum-scoped.cpp b/test/SemaCXX/enum-scoped.cpp
index cf579e1..8c4bfe7 100644
--- a/test/SemaCXX/enum-scoped.cpp
+++ b/test/SemaCXX/enum-scoped.cpp
@@ -103,3 +103,9 @@
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) { }
+}