This is an archive of the discontinued LLVM Phabricator instance.

[Sema] Fix decrement availability for built-in types
ClosedPublic

Authored by jkorous-apple on Mar 28 2018, 11:06 AM.

Details

Summary

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

Diff Detail

Repository
rC Clang

Event Timeline

jkorous-apple created this revision.Mar 28 2018, 11:06 AM
vsapsai added a subscriber: vsapsai.Apr 6 2018, 6:51 PM
vsapsai added inline comments.
test/SemaCXX/overloaded-builtin-operators.cpp
95–99

Looks like p3 for lr-- is a typo because p3 is about ++ while p4 is about --. It means the existing test didn't catch this bug. Not sure that adding another positive test will reliably prevent a regression in the future. Currently FloatRef is the type to expose the bug because FloatTy is the first type in ArithmeticTypes.

What if we add a negative test? I.e. something that would fail like

cannot decrement value of type 'BoolRef'

Also we can improve testing for p3 and test that BoolRef does support increment.

Added test for decrement being disabled for bool.
Fixed comment in test (will put into separate NFC commit).

Spot on with the negative test idea! Should've done that myself. Thanks.

vsapsai accepted this revision.Apr 10 2018, 10:07 AM

Looks good to me.

This revision is now accepted and ready to land.Apr 10 2018, 10:07 AM
This revision was automatically updated to reflect the committed changes.