r199627 - PR18551: accepts invalid strong enum to bool when operator! is used
Alp Toker
alp at nuanti.com
Sun Jan 19 23:20:23 PST 2014
Author: alp
Date: Mon Jan 20 01:20:22 2014
New Revision: 199627
URL: http://llvm.org/viewvc/llvm-project?rev=199627&view=rev
Log:
PR18551: accepts invalid strong enum to bool when operator! is used
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=199627&r1=199626&r2=199627&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Jan 20 01:20:22 2014
@@ -9711,7 +9711,7 @@ ExprResult Sema::CreateBuiltinUnaryOp(So
if (resultType->isDependentType())
break;
- if (resultType->isScalarType()) {
+ if (resultType->isScalarType() && !isScopedEnumerationType(resultType)) {
// C99 6.5.3.3p1: ok, fallthrough;
if (Context.getLangOpts().CPlusPlus) {
// C++03 [expr.unary.op]p8, C++0x [expr.unary.op]p9:
Modified: cfe/trunk/test/SemaCXX/enum-scoped.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/enum-scoped.cpp?rev=199627&r1=199626&r2=199627&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/enum-scoped.cpp (original)
+++ cfe/trunk/test/SemaCXX/enum-scoped.cpp Mon Jan 20 01:20:22 2014
@@ -272,6 +272,11 @@ namespace PR16900 {
A f(A a) { return -a; } // expected-error {{invalid argument type 'PR16900::A' to unary expression}}
}
+namespace PR18551 {
+ enum class A { A };
+ bool f() { return !A::A; } // expected-error {{invalid argument type 'PR18551::A' to unary expression}}
+}
+
namespace rdar15124329 {
enum class B : bool { F, T };
More information about the cfe-commits
mailing list