Don't allow unary negation on scoped enums.
authorEli Friedman <eli.friedman@gmail.com>
Fri, 16 Aug 2013 00:09:18 +0000 (00:09 +0000)
committerEli Friedman <eli.friedman@gmail.com>
Fri, 16 Aug 2013 00:09:18 +0000 (00:09 +0000)
PR16900.

llvm-svn: 188511

clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/enum-scoped.cpp

index 2edddbbc23d60b4f7b292ecdaeed445d6d9a1087..aaa82874386a1d8976757d31d2083eb4f1013f98 100644 (file)
@@ -9419,9 +9419,6 @@ ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc,
     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())
index d01000d22bb48a41e181601488cc3a9a4a410302..a9a6de9592edfdf433246a3ced8ac89bb7914fb4 100644 (file)
@@ -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}}
+}