In C++, one cannot assign from an arithmetic type to an enumeration
type. Fixes PR7051.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104475 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 5e2e732..f745352 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -4650,7 +4650,8 @@
return Incompatible;
}
- if (lhsType->isArithmeticType() && rhsType->isArithmeticType())
+ if (lhsType->isArithmeticType() && rhsType->isArithmeticType() &&
+ !(getLangOptions().CPlusPlus && lhsType->isEnumeralType()))
return Compatible;
if (isa<PointerType>(lhsType)) {
diff --git a/test/SemaCXX/enum.cpp b/test/SemaCXX/enum.cpp
index dc4a506..bfb5784 100644
--- a/test/SemaCXX/enum.cpp
+++ b/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 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'}}
+ }
+}