Author: dgregor
Date: Sun May 23 16:53:47 2010
New Revision: 104475

URL: http://llvm.org/viewvc/llvm-project?rev=104475&view=rev
Log:
In C++, one cannot assign from an arithmetic type to an enumeration
type. Fixes PR7051.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/enum.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=104475&r1=104474&r2=104475&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun May 23 16:53:47 2010
@@ -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)) {

Modified: cfe/trunk/test/SemaCXX/enum.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum.cpp?rev=104475&r1=104474&r2=104475&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enum.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum.cpp Sun May 23 16:53:47 2010
@@ -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'}}
+  }
+}


_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to