[PATCH] libstdc++: Use explicit cast to unsigned in std::rotr and std::rotl
Tomasz Kaminski
tkaminsk@redhat.com
Tue Jun 3 08:23:23 GMT 2025
On Mon, Jun 2, 2025 at 7:28 PM Jonathan Wakely <jwakely@redhat.com> wrote:
> This suppresses some -Wsign-conversion warnings from Clang when
> compiling with -Wsystem-headers.
>
> libstdc++-v3/ChangeLog:
>
> * include/std/bit (__rotl, __rotr): Use static_cast for
> conversion from int to unsigned.
> ---
>
> Tested x86_64-linux.
>
LGTM.
>
> libstdc++-v3/include/std/bit | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libstdc++-v3/include/std/bit b/libstdc++-v3/include/std/bit
> index 5187c96182f5..02d7189f1a3d 100644
> --- a/libstdc++-v3/include/std/bit
> +++ b/libstdc++-v3/include/std/bit
> @@ -166,7 +166,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> // Variant for power of two _Nd which the compiler can
> // easily pattern match.
> constexpr unsigned __uNd = _Nd;
> - const unsigned __r = __s;
> + const unsigned __r = static_cast<unsigned>(__s);
>
I would define the variable as const auto, given the cast.
> return (__x << (__r % __uNd)) | (__x >> ((-__r) % __uNd));
> }
> const int __r = __s % _Nd;
> @@ -188,7 +188,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
> // Variant for power of two _Nd which the compiler can
> // easily pattern match.
> constexpr unsigned __uNd = _Nd;
> - const unsigned __r = __s;
> + const unsigned __r = static_cast<unsigned>(__s);
> return (__x >> (__r % __uNd)) | (__x << ((-__r) % __uNd));
> }
> const int __r = __s % _Nd;
> --
> 2.49.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://gcc.gnu.org/pipermail/libstdc++/attachments/20250603/19c88a11/attachment-0001.htm>
More information about the Libstdc++
mailing list