[PATCH] D44988: [Sema] Fix decrement availability for built-in types

Phabricator via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 11 06:39:34 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rL329804: [Sema] Fix built-in decrement operator overload resolution (authored by jkorous, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D44988?vs=141865&id=141995#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D44988

Files:
  cfe/trunk/lib/Sema/SemaOverload.cpp
  cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp


Index: cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp
===================================================================
--- cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp
+++ cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp
@@ -62,6 +62,10 @@
   // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2));
 }
 
+struct BoolRef {
+  operator bool&();
+};
+
 struct ShortRef { // 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}}
@@ -73,6 +77,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 +92,19 @@
   operator E2&();
 };
 
-void g(ShortRef sr, LongRef lr, E2Ref e2_ref, XpmfRef pmf_ref) {
+void g(BoolRef br, ShortRef sr, LongRef lr, FloatRef fr, E2Ref e2_ref, XpmfRef pmf_ref) {
   // C++ [over.built]p3
   short s1 = sr++;
 
-  // C++ [over.built]p3
+  // C++ [over.built]p4
   long l1 = lr--;
 
+  // C++ [over.built]p4
+  float f1 = fr--;
+
+  // C++ [over.built]p4
+  bool b2 = br--; // expected-error{{cannot decrement value of type 'BoolRef'}}
+
   // C++ [over.built]p18
   short& sr1 = (sr *= lr);
   volatile long& lr1 = (lr *= sr);
Index: cfe/trunk/lib/Sema/SemaOverload.cpp
===================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp
+++ cfe/trunk/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.141995.patch
Type: text/x-patch
Size: 2346 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180411/738e3d32/attachment.bin>


More information about the llvm-commits mailing list