r188511 - Don't allow unary negation on scoped enums.

Eli Friedman eli.friedman at gmail.com
Thu Aug 15 17:09:18 PDT 2013


Author: efriedma
Date: Thu Aug 15 19:09:18 2013
New Revision: 188511

URL: http://llvm.org/viewvc/llvm-project?rev=188511&view=rev
Log:
Don't allow unary negation on scoped enums.

PR16900.

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

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=188511&r1=188510&r2=188511&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Aug 15 19:09:18 2013
@@ -9419,9 +9419,6 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
     if (resultType->isArithmeticType() || // C99 6.5.3.3p1
         resultType->isVectorType()) 
       break;
-    else if (getLangOpts().CPlusPlus && // C++ [expr.unary.op]p6-7
-             resultType->isEnumeralType())
-      break;
     else if (getLangOpts().CPlusPlus && // C++ [expr.unary.op]p6
              Opc == UO_Plus &&
              resultType->isPointerType())

Modified: cfe/trunk/test/SemaCXX/enum-scoped.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum-scoped.cpp?rev=188511&r1=188510&r2=188511&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enum-scoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum-scoped.cpp Thu Aug 15 19:09:18 2013
@@ -266,3 +266,8 @@ namespace PR15633 {
   struct B { enum class E; };
   template<typename T> enum class B::E { e }; // expected-error {{enumeration cannot be a template}}
 }
+
+namespace PR16900 {
+  enum class A;
+  A f(A a) { return -a; } // expected-error {{invalid argument type 'PR16900::A' to unary expression}}
+}





More information about the cfe-commits mailing list