- Changed parameters type in std::rotr and std::rorl functions from unsigned int to int.
- Implemented behaviour for negative parameter values.
Fixes #64544
Differential D157569
[libc++] Fix the signature of std::rotl and std::rotr DKay7 on Aug 9 2023, 7:10 PM. Authored by
Details
Fixes #64544
Diff Detail
Event TimelineComment Actions Please add tests in libcxx/test/std/numerics/bit/bitops.rot/rotr.pass.cpp for this change.
Comment Actions I implemented the behavior for negative values in __rotr and thought that now std::rotl and std::rotr could be implemented as follows: template <__libcpp_unsigned_integer _Tp> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotl(_Tp __t, int __cnt) noexcept { return std::__rotr(__t, -__cnt); } template <__libcpp_unsigned_integer _Tp> [[nodiscard]] _LIBCPP_HIDE_FROM_ABI constexpr _Tp rotr(_Tp __t, int __cnt) noexcept { return std::__rotr(__t, __cnt); } This works for positive values, because rotl is the same as rotr with a negative value and vice versa. However, it doesn't seem very obvious and might be even confusing, so I wanted to find out if it's worth doing so. Thank you. Comment Actions
Comment Actions Updating D157569: Fixed issue #64544 ([libc++] std::rotl and std::rotr have the wrong signature)
Comment Actions It looks like __bit/rotate.h is now formatted. Please remove it from libcxx/utils/data/ignore_format.txt. LGTM with passing CI. I guess you don't have commit access? In that case, please provide "Your Name" <your.email@address> for attribution. Comment Actions AIX build has failed with "There is not enough space in the file system" error. Actually, I have no idea how to deal with it. |
It looks like your patch is missing the last commit. I'd recommend squashing the two into one and upload the resulting patch again.