[PATCH] D44988: [Sema] Fix decrement availability for built-in types
Jan Korous via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 28 11:07:19 PDT 2018
jkorous-apple created this revision.
jkorous-apple added reviewers: speziale.ettore, arphaman.
Herald added a subscriber: cfe-commits.
C++ [over.built]p4:
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);
The bool type is in position LastPromotedIntegralType in BuiltinOperatorOverloadBuilder::getArithmeticType::ArithmeticTypes, but addPlusPlusMinusMinusArithmeticOverloads() is expecting it at position 0.
Original patch by Ettore Speziale.
rdar://problem/34255516
Repository:
rC Clang
https://reviews.llvm.org/D44988
Files:
lib/Sema/SemaOverload.cpp
test/SemaCXX/overloaded-builtin-operators.cpp
Index: test/SemaCXX/overloaded-builtin-operators.cpp
===================================================================
--- test/SemaCXX/overloaded-builtin-operators.cpp
+++ test/SemaCXX/overloaded-builtin-operators.cpp
@@ -73,6 +73,10 @@
operator volatile long&();
};
+struct FloatRef {
+ operator float&();
+};
+
struct XpmfRef { // expected-note{{candidate function (the implicit copy assignment operator) not viable}}
#if __cplusplus >= 201103L // C++11 or later
// expected-note at -2 {{candidate function (the implicit move assignment operator) not viable}}
@@ -84,13 +88,16 @@
operator E2&();
};
-void g(ShortRef sr, LongRef lr, E2Ref e2_ref, XpmfRef pmf_ref) {
+void g(ShortRef sr, LongRef lr, FloatRef fr, E2Ref e2_ref, XpmfRef pmf_ref) {
// C++ [over.built]p3
short s1 = sr++;
// C++ [over.built]p3
long l1 = lr--;
+ // C++ [over.built]p4
+ float f1 = fr--;
+
// C++ [over.built]p18
short& sr1 = (sr *= lr);
volatile long& lr1 = (lr *= sr);
Index: lib/Sema/SemaOverload.cpp
===================================================================
--- lib/Sema/SemaOverload.cpp
+++ lib/Sema/SemaOverload.cpp
@@ -7796,10 +7796,12 @@
if (!HasArithmeticOrEnumeralCandidateType)
return;
- for (unsigned Arith = (Op == OO_PlusPlus? 0 : 1);
- Arith < NumArithmeticTypes; ++Arith) {
+ for (unsigned Arith = 0; Arith < NumArithmeticTypes; ++Arith) {
+ const auto TypeOfT = ArithmeticTypes[Arith];
+ if (Op == OO_MinusMinus && TypeOfT == S.Context.BoolTy)
+ continue;
addPlusPlusMinusMinusStyleOverloads(
- ArithmeticTypes[Arith],
+ TypeOfT,
VisibleTypeConversionsQuals.hasVolatile(),
VisibleTypeConversionsQuals.hasRestrict());
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44988.140107.patch
Type: text/x-patch
Size: 1756 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180328/59589f1c/attachment.bin>
More information about the cfe-commits
mailing list