Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix datatype of underlying data to avoid signed/unsigned compiler warning with MSVC #3647

Merged
merged 1 commit into from
Sep 19, 2023

Conversation

saschasc
Copy link
Contributor

The following line leads to a signed/unsigned error on newer MSVC compilers (14.36.32532).

https://github.com/fmtlib/fmt/blame/f6ca4ea1990af67e00358cfe83c19f5aa4df5f19/include/fmt/format.h#L3036

Casting the value to the underlying datatype uint32_t solves the compiler issue.

std::uninitialized_fill_n(bigits_.data(), exp_difference, static_cast<uint32_t>(0));

@saschasc saschasc changed the title Use datatype of underlying data Fix datatype of underlying data to avoid signed/unsigned compiler warning with MSVC Sep 18, 2023
@saschasc
Copy link
Contributor Author

For completeness sake the exact error.

Remarks: I've also tested it with the newest version of fmt (here with 10.0.0 it's the same).

C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\xutility(251): error C2220: the following warning is treated as an error
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\xutility(261): note: see reference to function template instantiation '_Ty *std::construct_at<_Ty,const _Tval&,0x0>(_Ty *const ,const _Tval &) noexcept(<expr>)' being compiled
        with
        [
            _Ty=fmt::v10::detail::bigint::bigit,
            _Tval=int
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\xmemory(1593): note: see reference to function template instantiation 'void std::_Construct_in_place<T,const _Tval&>(_Ty &,const _Tval &) noexcept' being compiled
        with
        [
            T=fmt::v10::detail::bigint::bigit,
            _Tval=int,
            _Ty=fmt::v10::detail::bigint::bigit
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\memory(462): note: see reference to function template instantiation 'void std::_Uninitialized_backout<_NoThrowFwdIt>::_Emplace_back<const _Tval&>(const _Tval &)' being compiled
        with
        [
            _NoThrowFwdIt=fmt::v10::detail::bigint::bigit *,
            _Tval=int
        ]
C:\Users\user\.conan\data\fmt\10.0.0\_\_\package\a666b826fb67069936c75332b1ff9cfb68adf0da\include\fmt/format.h(3244): note: see reference to function template instantiation '_NoThrowFwdIt *std::uninitialized_fill_n<T*,int,int>(_NoThrowFwdIt,const _Diff,const _Tval &)' being compiled
        with
        [
            _NoThrowFwdIt=fmt::v10::detail::bigint::bigit *,
            T=fmt::v10::detail::bigint::bigit,
            _Diff=int,
            _Tval=int
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\xutility(251): warning C4365: 'initializing': conversion from 'const _Tval' to '_Ty', signed/unsigned mismatch
        with
        [
            _Tval=int
        ]
        and
        [
            _Ty=fmt::v10::detail::bigint::bigit
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\xutility(265): warning C4365: 'initializing': conversion from 'const _Tval' to 'T', signed/unsigned mismatch
        with
        [
            _Tval=int
        ]
        and
        [
            T=fmt::v10::detail::bigint::bigit
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\xutility(252): warning C4365: 'initializing': conversion from 'const _Tval' to '_Ty', signed/unsigned mismatch
        with
        [
            _Tval=int
        ]
        and
        [
            _Ty=fmt::v10::detail::bigint::bigit
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\xutility(261): note: see reference to function template instantiation '_Ty *std::construct_at<_Ty,const _Tval&,0x0>(_Ty *const ,const _Tval &) noexcept' being compiled
        with
        [
            _Ty=fmt::v10::detail::bigint::bigit,
            _Tval=int
        ]
C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.36.32532\include\xmemory(1593): note: see reference to function template instantiation 'void std::_Construct_in_place<T,const _Tval&>(_Ty &,const _Tval &) noexcept' being compiled
        with
        [
            T=fmt::v10::detail::bigint::bigit,
            _Tval=int,
            _Ty=fmt::v10::detail::bigint::bigit
        ]

@@ -3033,7 +3033,7 @@ class bigint {
bigits_.resize(to_unsigned(num_bigits + exp_difference));
for (int i = num_bigits - 1, j = i + exp_difference; i >= 0; --i, --j)
bigits_[j] = bigits_[i];
std::uninitialized_fill_n(bigits_.data(), exp_difference, 0);
std::uninitialized_fill_n(bigits_.data(), exp_difference, static_cast<uint32_t>(0));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's replace the cast with 0u.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I've tested and adapted it.

@vitaut vitaut merged commit 8ef4db4 into fmtlib:master Sep 19, 2023
40 checks passed
@vitaut
Copy link
Contributor

vitaut commented Sep 19, 2023

thanks

@saschasc
Copy link
Contributor Author

Thanks for merging. I hope a new release is planned soon.

@saschasc saschasc deleted the signed-unsigned-fix branch September 19, 2023 14:33
ckerr pushed a commit to transmission/fmt that referenced this pull request Nov 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants