r254122 - P0002R1: increment on expressions of type bool is no longer allowed in C++1z.

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 25 18:16:38 PST 2015


Author: rsmith
Date: Wed Nov 25 20:16:37 2015
New Revision: 254122

URL: http://llvm.org/viewvc/llvm-project?rev=254122&view=rev
Log:
P0002R1: increment on expressions of type bool is no longer allowed in C++1z.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/CXX/drs/dr1xx.cpp
    cfe/trunk/test/SemaCXX/deprecated.cpp
    cfe/trunk/www/cxx_status.html

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=254122&r1=254121&r2=254122&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Nov 25 20:16:37 2015
@@ -187,7 +187,8 @@ def CXX14Compat : DiagGroup<"c++14-compa
 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-el
 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">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=254122&r1=254121&r2=254122&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Nov 25 20:16:37 2015
@@ -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<DeprecatedIncrementBool>;
+  "incrementing expression of type bool is deprecated and "
+  "incompatible with C++1z">, InGroup<DeprecatedIncrementBool>;
+def ext_increment_bool : ExtWarn<
+  "ISO C++1z does not allow incrementing expression of type bool">,
+  DefaultError, InGroup<IncrementBool>;
 def err_increment_decrement_enum : Error<
   "cannot %select{decrement|increment}0 expression of enum type %1">;
 def err_catch_incomplete_ptr : Error<

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=254122&r1=254121&r2=254122&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Nov 25 20:16:37 2015
@@ -9680,7 +9680,9 @@ static QualType CheckIncrementDecrementO
       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;

Modified: cfe/trunk/test/CXX/drs/dr1xx.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr1xx.cpp?rev=254122&r1=254121&r2=254122&view=diff
==============================================================================
--- cfe/trunk/test/CXX/drs/dr1xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr1xx.cpp Wed Nov 25 20:16:37 2015
@@ -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
   }
 }
 

Modified: cfe/trunk/test/SemaCXX/deprecated.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/deprecated.cpp?rev=254122&r1=254121&r2=254122&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/deprecated.cpp (original)
+++ cfe/trunk/test/SemaCXX/deprecated.cpp Wed Nov 25 20:16:37 2015
@@ -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 at -2 {{ISO C++1z does not allow incrementing expression of type bool}}
+#else
+  // expected-warning at -4 {{incrementing expression of type bool is deprecated}}
+#endif
+
+  b++;
+#if __cplusplus > 201402L
+  // expected-error at -2 {{ISO C++1z does not allow incrementing expression of type bool}}
+#else
+  // expected-warning at -4 {{incrementing expression of type bool is deprecated}}
+#endif
 
   char *p = "foo";
 #if __cplusplus < 201103L

Modified: cfe/trunk/www/cxx_status.html
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/www/cxx_status.html?rev=254122&r1=254121&r2=254122&view=diff
==============================================================================
--- cfe/trunk/www/cxx_status.html (original)
+++ cfe/trunk/www/cxx_status.html Wed Nov 25 20:16:37 2015
@@ -601,7 +601,7 @@ as the draft C++1z standard evolves.</p>
     <tr>
       <td>Remove deprecated <tt>bool</tt> increment</td>
       <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0002r1.html">P0002R1</a></td>
-      <td class="none" align="center">No</td>
+      <td class="svn" align="center">Clang 3.8</td>
     </tr>
     <tr>
       <td>Make exception specifications part of the type system</td>
@@ -609,7 +609,7 @@ as the draft C++1z standard evolves.</p>
       <td class="none" align="center">No</td>
     </tr>
     <tr>
-      <td><tt>__has_include</tt></td>
+      <td><tt>__has_include</tt> in preprocessor conditionals</td>
       <td><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0061.html">P0061R1</a></td>
       <td class="full" align="center">Yes</td>
     </tr>




More information about the cfe-commits mailing list