From 2f835ca26aad970be44227d40269db45e73d0a08 Mon Sep 17 00:00:00 2001 From: Eli Friedman Date: Fri, 16 Aug 2013 00:09:18 +0000 Subject: [PATCH] Don't allow unary negation on scoped enums. PR16900. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@188511 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExpr.cpp | 3 --- test/SemaCXX/enum-scoped.cpp | 5 +++++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 2edddbbc23..aaa8287438 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -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()) diff --git a/test/SemaCXX/enum-scoped.cpp b/test/SemaCXX/enum-scoped.cpp index d01000d22b..a9a6de9592 100644 --- a/test/SemaCXX/enum-scoped.cpp +++ b/test/SemaCXX/enum-scoped.cpp @@ -266,3 +266,8 @@ namespace PR15633 { struct B { enum class E; }; template 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}} +} -- 2.40.0