diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 5e2e73257254..f745352d998f 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4650,7 +4650,8 @@ Sema::CheckAssignmentConstraints(QualType lhsType, QualType rhsType) { return Incompatible; } - if (lhsType->isArithmeticType() && rhsType->isArithmeticType()) + if (lhsType->isArithmeticType() && rhsType->isArithmeticType() && + !(getLangOptions().CPlusPlus && lhsType->isEnumeralType())) return Compatible; if (isa(lhsType)) { diff --git a/clang/test/SemaCXX/enum.cpp b/clang/test/SemaCXX/enum.cpp index dc4a506dda21..bfb5784dd161 100644 --- a/clang/test/SemaCXX/enum.cpp +++ b/clang/test/SemaCXX/enum.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -fsyntax-only -pedantic -std=c++98 -verify -triple x86_64-apple-darwin %s - enum E { Val1, Val2 @@ -71,3 +70,12 @@ namespace PR6061 { namespace Conditional { enum a { A }; a x(const enum a x) { return 1?x:A; } } + +namespace PR7051 { + enum E { e0 }; + void f() { + E e; + e = 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}} + e |= 1; // expected-error{{assigning to 'PR7051::E' from incompatible type 'int'}} + } +}