[PATCH] D45569: [Sema] Disable built-in increment operator for bool in overload resolution in C++17
Jan Korous via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Apr 18 06:43:06 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC330254: [Sema] Disable built-in increment operator for bool in overload resolution in… (authored by jkorous, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D45569?vs=142167&id=142929#toc
Repository:
rC Clang
https://reviews.llvm.org/D45569
Files:
lib/Sema/SemaOverload.cpp
test/SemaCXX/overloaded-builtin-operators-cxx17.cpp
Index: test/SemaCXX/overloaded-builtin-operators-cxx17.cpp
===================================================================
--- test/SemaCXX/overloaded-builtin-operators-cxx17.cpp
+++ test/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 was removed in C++17.
+ bool b = br++; // expected-error{{cannot increment value of type 'BoolRef'}}
+}
\ No newline at end of file
Index: lib/Sema/SemaOverload.cpp
===================================================================
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -7782,11 +7782,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);
@@ -7805,8 +7807,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(),
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45569.142929.patch
Type: text/x-patch
Size: 1897 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180418/a48a970e/attachment.bin>
More information about the cfe-commits
mailing list