r329804 - [Sema] Fix built-in decrement operator overload resolution

Richard Smith via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 25 10:22:02 PDT 2018


On 12 April 2018 at 07:20, Jan Korous via cfe-commits <
cfe-commits at lists.llvm.org> wrote:

> Hi Richard,
>
> Here you are:
> https://reviews.llvm.org/D45569
>
> I am now thinking if it makes sense to output this warning for pre-17
> standards:
>
> warning: incrementing expression of type bool is deprecated and
> incompatible with C++17
>
> Produced in:
>
> SemaExpr.cpp
>
> static QualType CheckIncrementDecrementOperand
>
>     // Increment of bool sets it to true, but is deprecated.
>     S.Diag(OpLoc, S.getLangOpts().CPlusPlus17 ? diag::ext_increment_bool
>                                               : diag::warn_increment_bool)
>
> What do you think?
>

Seems like a good idea to me, thanks!


> Jan
>
> On 11 Apr 2018, at 15:19, Richard Smith <richard at metafoo.co.uk> wrote:
>
> While you're here... ++ should not be available for bool in C++17 onwards.
> :)
>
> On Wed, 11 Apr 2018, 14:39 Jan Korous via cfe-commits, <
> cfe-commits at lists.llvm.org> wrote:
>
>> Author: jkorous
>> Date: Wed Apr 11 06:36:29 2018
>> New Revision: 329804
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=329804&view=rev
>> Log:
>> [Sema] Fix built-in decrement operator overload resolution
>>
>> 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() was expecting it at position
>> 0.
>>
>> Differential Revision: https://reviews.llvm.org/D44988
>>
>> rdar://problem/34255516
>>
>> Modified:
>>     cfe/trunk/lib/Sema/SemaOverload.cpp
>>     cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp
>>
>> Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/
>> SemaOverload.cpp?rev=329804&r1=329803&r2=329804&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
>> +++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Apr 11 06:36:29 2018
>> @@ -7796,10 +7796,12 @@ public:
>>      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());
>>      }
>>
>> Modified: cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/
>> SemaCXX/overloaded-builtin-operators.cpp?rev=329804&r1=
>> 329803&r2=329804&view=diff
>> ============================================================
>> ==================
>> --- cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp (original)
>> +++ cfe/trunk/test/SemaCXX/overloaded-builtin-operators.cpp Wed Apr 11
>> 06:36:29 2018
>> @@ -62,6 +62,10 @@ void f(Short s, Long l, Enum1 e1, Enum2
>>    // 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 @@ struct LongRef {
>>    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 @@ struct E2Ref {
>>    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);
>>
>>
>> _______________________________________________
>> cfe-commits mailing list
>> cfe-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180425/b14cc0b8/attachment.html>


More information about the cfe-commits mailing list