From: Douglas Gregor Date: Tue, 1 Mar 2011 17:16:20 +0000 (+0000) Subject: Implement comparison of C++0x scoped enumeration types. Fixes PR9333. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=90566c0e7b61de9bdfdf66f6dee440adb4e5b631;p=clang 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 ae0ed3e4f1..321e96f1e7 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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); } diff --git a/test/SemaCXX/enum-scoped.cpp b/test/SemaCXX/enum-scoped.cpp index cf579e180f..8c4bfe72d3 100644 --- a/test/SemaCXX/enum-scoped.cpp +++ b/test/SemaCXX/enum-scoped.cpp @@ -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) { } +}