From: Richard Smith Date: Thu, 26 Nov 2015 02:16:37 +0000 (+0000) Subject: P0002R1: increment on expressions of type bool is no longer allowed in C++1z. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8677278cfa4f0c17cbfdaf28fd59d47853c63860;p=clang P0002R1: increment on expressions of type bool is no longer allowed in C++1z. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@254122 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td index 8be6c5ee02..64add07b17 100644 --- a/include/clang/Basic/DiagnosticGroups.td +++ b/include/clang/Basic/DiagnosticGroups.td @@ -187,7 +187,8 @@ def CXX14Compat : DiagGroup<"c++14-compat", [CXXPre1zCompat]>; def CXX14CompatPedantic : DiagGroup<"c++14-compat-pedantic", [CXXPre1zCompatPedantic]>; -def CXX1zCompat : DiagGroup<"c++1z-compat", [DeprecatedRegister]>; +def CXX1zCompat : DiagGroup<"c++1z-compat", [DeprecatedRegister, + DeprecatedIncrementBool]>; def : DiagGroup<"effc++">; def DivZero : DiagGroup<"division-by-zero">; @@ -204,6 +205,7 @@ def DanglingElse: DiagGroup<"dangling-else">; def DanglingField : DiagGroup<"dangling-field">; def DistributedObjectModifiers : DiagGroup<"distributed-object-modifiers">; def FlagEnum : DiagGroup<"flag-enum">; +def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>; def InfiniteRecursion : DiagGroup<"infinite-recursion">; def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">; def IgnoredQualifiers : DiagGroup<"ignored-qualifiers">; diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index 91ccf77487..9585110f96 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -5727,8 +5727,11 @@ def note_member_declared_here : Note< "member %0 declared here">; def err_decrement_bool : Error<"cannot decrement expression of type bool">; def warn_increment_bool : Warning< - "incrementing expression of type bool is deprecated">, - InGroup; + "incrementing expression of type bool is deprecated and " + "incompatible with C++1z">, InGroup; +def ext_increment_bool : ExtWarn< + "ISO C++1z does not allow incrementing expression of type bool">, + DefaultError, InGroup; def err_increment_decrement_enum : Error< "cannot %select{decrement|increment}0 expression of enum type %1">; def err_catch_incomplete_ptr : Error< diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp index 20f1bdbf5e..3481f73e69 100644 --- a/lib/Sema/SemaExpr.cpp +++ b/lib/Sema/SemaExpr.cpp @@ -9680,7 +9680,9 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op, return QualType(); } // Increment of bool sets it to true, but is deprecated. - S.Diag(OpLoc, diag::warn_increment_bool) << Op->getSourceRange(); + S.Diag(OpLoc, S.getLangOpts().CPlusPlus1z ? diag::ext_increment_bool + : diag::warn_increment_bool) + << Op->getSourceRange(); } else if (S.getLangOpts().CPlusPlus && ResType->isEnumeralType()) { // Error on enum increments and decrements in C++ mode S.Diag(OpLoc, diag::err_increment_decrement_enum) << IsInc << ResType; diff --git a/test/CXX/drs/dr1xx.cpp b/test/CXX/drs/dr1xx.cpp index 377bfc94ff..47d1494ec7 100644 --- a/test/CXX/drs/dr1xx.cpp +++ b/test/CXX/drs/dr1xx.cpp @@ -524,8 +524,13 @@ namespace dr143 { // dr143: yes namespace dr145 { // dr145: yes void f(bool b) { +#if __cplusplus <= 201402L ++b; // expected-warning {{deprecated}} b++; // expected-warning {{deprecated}} +#else + ++b; // expected-error {{increment}} + b++; // expected-error {{increment}} +#endif } } diff --git a/test/SemaCXX/deprecated.cpp b/test/SemaCXX/deprecated.cpp index 732c015e78..4ce0589687 100644 --- a/test/SemaCXX/deprecated.cpp +++ b/test/SemaCXX/deprecated.cpp @@ -28,7 +28,19 @@ void stuff() { int k = to_int(n); // no-warning bool b; - ++b; // expected-warning {{incrementing expression of type bool is deprecated}} + ++b; +#if __cplusplus > 201402L + // expected-error@-2 {{ISO C++1z does not allow incrementing expression of type bool}} +#else + // expected-warning@-4 {{incrementing expression of type bool is deprecated}} +#endif + + b++; +#if __cplusplus > 201402L + // expected-error@-2 {{ISO C++1z does not allow incrementing expression of type bool}} +#else + // expected-warning@-4 {{incrementing expression of type bool is deprecated}} +#endif char *p = "foo"; #if __cplusplus < 201103L diff --git a/www/cxx_status.html b/www/cxx_status.html index c41f1196fe..2e9c2985e0 100644 --- a/www/cxx_status.html +++ b/www/cxx_status.html @@ -601,7 +601,7 @@ as the draft C++1z standard evolves.

Remove deprecated bool increment P0002R1 - No + Clang 3.8 Make exception specifications part of the type system @@ -609,7 +609,7 @@ as the draft C++1z standard evolves.

No - __has_include + __has_include in preprocessor conditionals P0061R1 Yes