r330254 - [Sema] Disable built-in increment operator for bool in overload resolution in C++17

Jan Korous via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 18 06:38:39 PDT 2018


Author: jkorous
Date: Wed Apr 18 06:38:39 2018
New Revision: 330254

URL: http://llvm.org/viewvc/llvm-project?rev=330254&view=rev
Log:
[Sema] Disable built-in increment operator for bool in overload resolution in C++17

Following: https://llvm.org/svn/llvm-project/cfe/trunk@329804

For C++17 the wording of [over.built] p4 excluded bool:

For every pair (T , vq), where T is an arithmetic type other than bool, there exist
candidate operator functions of the form
  vq T & operator++(vq T &);
  T operator++(vq T &, int);

Differential Revision: https://reviews.llvm.org/D45569

Added:
    cfe/trunk/test/SemaCXX/overloaded-builtin-operators-cxx17.cpp
Modified:
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=330254&r1=330253&r2=330254&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Apr 18 06:38:39 2018
@@ -7782,11 +7782,13 @@ public:
     InitArithmeticTypes();
   }
 
+  // Increment is deprecated for bool since C++17.
+  //
   // C++ [over.built]p3:
   //
-  //   For every pair (T, VQ), where T is an arithmetic type, and VQ
-  //   is either volatile or empty, there exist candidate operator
-  //   functions of the form
+  //   For every pair (T, VQ), where T is an arithmetic type other
+  //   than bool, and VQ is either volatile or empty, there exist
+  //   candidate operator functions of the form
   //
   //       VQ T&      operator++(VQ T&);
   //       T          operator++(VQ T&, int);
@@ -7805,8 +7807,12 @@ public:
 
     for (unsigned Arith = 0; Arith < NumArithmeticTypes; ++Arith) {
       const auto TypeOfT = ArithmeticTypes[Arith];
-      if (Op == OO_MinusMinus && TypeOfT == S.Context.BoolTy)
-        continue;
+      if (TypeOfT == S.Context.BoolTy) {
+        if (Op == OO_MinusMinus)
+          continue;
+        if (Op == OO_PlusPlus && S.getLangOpts().CPlusPlus17)
+          continue;
+      }
       addPlusPlusMinusMinusStyleOverloads(
         TypeOfT,
         VisibleTypeConversionsQuals.hasVolatile(),

Added: cfe/trunk/test/SemaCXX/overloaded-builtin-operators-cxx17.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/overloaded-builtin-operators-cxx17.cpp?rev=330254&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/overloaded-builtin-operators-cxx17.cpp (added)
+++ cfe/trunk/test/SemaCXX/overloaded-builtin-operators-cxx17.cpp Wed Apr 18 06:38:39 2018
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -fsyntax-only -fshow-overloads=best -verify -triple x86_64-linux-gnu -std=c++17 %s
+
+struct BoolRef {
+  operator bool&();
+};
+
+void foo(BoolRef br) {
+  // C++ [over.built]p3: Increment for bool was removed in C++17.
+  bool b = br++; // expected-error{{cannot increment value of type 'BoolRef'}}
+}
\ No newline at end of file




More information about the cfe-commits mailing list