jkorous-apple created this revision.
jkorous-apple added a reviewer: rsmith.
Herald added a subscriber: cfe-commits.
Advertising
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);
Repository:
rC Clang
https://reviews.llvm.org/D45569
Files:
Sema/SemaOverload.cpp
SemaCXX/overloaded-builtin-operators-cxx17.cpp
Index: SemaCXX/overloaded-builtin-operators-cxx17.cpp
===================================================================
--- /dev/null
+++ SemaCXX/overloaded-builtin-operators-cxx17.cpp
@@ -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 got deprecated in C++17.
+ bool b = br++; // expected-error{{cannot increment value of type 'BoolRef'}}
+}
\ No newline at end of file
Index: Sema/SemaOverload.cpp
===================================================================
--- Sema/SemaOverload.cpp
+++ Sema/SemaOverload.cpp
@@ -7775,11 +7775,13 @@
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);
@@ -7798,8 +7800,12 @@
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(),
Index: SemaCXX/overloaded-builtin-operators-cxx17.cpp
===================================================================
--- /dev/null
+++ SemaCXX/overloaded-builtin-operators-cxx17.cpp
@@ -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 got deprecated in C++17.
+ bool b = br++; // expected-error{{cannot increment value of type 'BoolRef'}}
+}
\ No newline at end of file
Index: Sema/SemaOverload.cpp
===================================================================
--- Sema/SemaOverload.cpp
+++ Sema/SemaOverload.cpp
@@ -7775,11 +7775,13 @@
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);
@@ -7798,8 +7800,12 @@
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(),
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits