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

[regression?] format_n(wchar_t*) results in warning C4244 #1707

Closed
TheQwertiest opened this issue May 29, 2020 · 5 comments
Closed

[regression?] format_n(wchar_t*) results in warning C4244 #1707

TheQwertiest opened this issue May 29, 2020 · 5 comments

Comments

@TheQwertiest
Copy link
Contributor

TheQwertiest commented May 29, 2020

Repro code:

#define FMT_HEADER_ONLY
#include <fmt/format.h>

#include <vector>

int main()
{
    std::vector<wchar_t> buffer(40);
    fmt::format_to_n( buffer.data(), buffer.size(), L"(unknown)" );
    return 0;
}

Compiler: VS 19.26.28805 x64
Compile cmd: cl.exe test.cpp -Ipath_to_fmt_include /std:c++17 /EHsc
Error/warning message:

Click me

Microsoft (R) C/C++ Optimizing Compiler Version 19.26.28805 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp
xmemory(204): warning C4244: 'initializing': conversion from 'const Char' to '_Ty', possible loss of data
        with
        [
            Char=wchar_t
        ]
        and
        [
            _Ty=char
        ]
xmemory(1427): note: see reference to function template instantiation 'void std::_Construct_in_place<T,const Char&>(_Ty &,const Char &) noexcept' being compiled
        with
        [
            T=char,
            Char=wchar_t,
            _Ty=char
        ]
xmemory(1593): note: see reference to function template instantiation 'void std::_Uninitialized_backout<_NoThrowFwdIt>::_Emplace_back<const Char&>(const Char &)' being compiled
        with
        [
            _NoThrowFwdIt=char *,
            Char=wchar_t
        ]
xmemory(1593): note: see reference to function template instantiation 'void std::_Uninitialized_backout<_NoThrowFwdIt>::_Emplace_back<const Char&>(const Char &)' being compiled
        with
        [
            _NoThrowFwdIt=char *,
            Char=wchar_t
        ]
fmt\format.h(1568): note: see reference to function template instantiation '_NoThrowFwdIt std::uninitialized_copy<const Char*,T*>(const _InIt,const _InIt,_NoThrowFwdIt)' being compiled
        with
        [
            _NoThrowFwdIt=char *,
            Char=wchar_t,
            T=char,
            _InIt=const wchar_t *
        ]
fmt\format.h(1534): note: while compiling class template member function 'void fmt::v6::detail::int_writer<fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>>,wchar_t,uint_type>::on_num(void)'
        with
        [
            OutputIt=wchar_t *
        ]
fmt\format.h(1240): note: see reference to function template instantiation 'void fmt::v6::detail::int_writer<fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>>,wchar_t,uint_type>::on_num(void)' being compiled
        with
        [
            OutputIt=wchar_t *
        ]
fmt\format.h(1746): note: see reference to class template instantiation 'fmt::v6::detail::int_writer<fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>>,wchar_t,uint_type>' being compiled
        with
        [
            OutputIt=wchar_t *
        ]
fmt\format.h(1822): note: see reference to function template instantiation 'void fmt::v6::detail::arg_formatter_base<Range,fmt::v6::detail::error_handler>::write_int<T>(T,const fmt::v6::basic_format_specs<wchar_t> &)' being compiled
        with
        [
            Range=range,
            T=__int64
        ]
fmt\format.h(1822): note: see reference to function template instantiation 'void fmt::v6::detail::arg_formatter_base<Range,fmt::v6::detail::error_handler>::write_int<T>(T,const fmt::v6::basic_format_specs<wchar_t> &)' being compiled
        with
        [
            Range=range,
            T=__int64
        ]
fmt\core.h(1170): note: see reference to function template instantiation 'fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>> fmt::v6::detail::arg_formatter_base<Range,fmt::v6::detail::error_handler>::operator ()<__int64,0>(T)' being compiled
        with
        [
            OutputIt=wchar_t *,
            Range=range,
            T=__int64
        ]
fmt\core.h(1170): note: see reference to function template instantiation 'fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>> fmt::v6::detail::arg_formatter_base<Range,fmt::v6::detail::error_handler>::operator ()<__int64,0>(T)' being compiled
        with
        [
            OutputIt=wchar_t *,
            Range=range,
            T=__int64
        ]
fmt\format.h(3176): note: see reference to function template instantiation 'fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>> fmt::v6::visit_format_arg<ArgFormatter,Context>(Visitor &&,const fmt::v6::basic_format_arg<Context> &)' being compiled
        with
        [
            OutputIt=wchar_t *,
            ArgFormatter=fmt::v6::arg_formatter<range>,
            Context=context,
            Visitor=fmt::v6::arg_formatter<range>
        ]
fmt\format.h(3395): note: see reference to function template instantiation 'fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>> fmt::v6::vformat_to<fmt::v6::arg_formatter<range>,wchar_t,fmt::v6::basic_format_context<fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>>,wchar_t>>(fmt::v6::detail::output_range<fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>>,wchar_t>,fmt::v6::basic_string_view<wchar_t>,fmt::v6::basic_format_args<fmt::v6::basic_format_context<fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>>,wchar_t>>,fmt::v6::detail::locale_ref)' being compiled
        with
        [
            OutputIt=wchar_t *
        ]
fmt\format.h(3449): note: see reference to function template instantiation 'OutputIt fmt::v6::vformat_to<fmt::v6::basic_string_view<wchar_t>,fmt::v6::detail::truncating_iterator<wchar_t*,std::integral_constant<bool,false>>,,0>(OutputIt,const S &,fmt::v6::basic_format_args<fmt::v6::basic_format_context<OutputIt,wchar_t>>)' being compiled
        with
        [
            OutputIt=fmt::v6::detail::truncating_iterator<wchar_t *,std::integral_constant<bool,false>>,
            S=fmt::v6::basic_string_view<wchar_t>
        ]
fmt\format.h(3467): note: see reference to function template instantiation 'fmt::v6::format_to_n_result<_Ty *> fmt::v6::vformat_to_n<OutputIt,wchar_t,,0>(OutputIt,size_t,fmt::v6::basic_string_view<wchar_t>,fmt::v6::basic_format_args<fmt::v6::basic_format_context<fmt::v6::detail::truncating_iterator<OutputIt,std::integral_constant<bool,false>>,wchar_t>>)' being compiled
        with
        [
            _Ty=wchar_t,
            OutputIt=wchar_t *
        ]
test.cpp(9): note: see reference to function template instantiation 'fmt::v6::format_to_n_result<_Ty *> fmt::v6::format_to_n<_Ty*,wchar_t[10],,0>(OutputIt,size_t,const S (&))' being compiled
        with
        [
            _Ty=wchar_t,
            OutputIt=wchar_t *,
            S=wchar_t [10]
        ]
xutility(3778): warning C4244: '=': conversion from '_Elem' to 'T', possible loss of data
        with
        [
            _Elem=wchar_t
        ]
        and
        [
            T=char
        ]
xutility(3814): note: see reference to function template instantiation '_OutIt std::_Copy_unchecked<_Iter,_NoThrowFwdIt>(_InIt,_InIt,_OutIt)' being compiled
        with
        [
            _OutIt=char *,
            _Iter=wchar_t *,
            _NoThrowFwdIt=char *,
            _InIt=wchar_t *
        ]
fmt\format.h(563): note: see reference to function template instantiation '_OutIt std::copy<InputIt,OutputIt>(_InIt,_InIt,_OutIt)' being compiled
        with
        [
            _OutIt=char *,
            InputIt=wchar_t *,
            OutputIt=char *,
            _InIt=wchar_t *
        ]
fmt\format.h(929): note: see reference to function template instantiation 'OutputIt fmt::v6::detail::copy_str<Char,Char*,Iterator,0>(InputIt,InputIt,OutputIt)' being compiled
        with
        [
            OutputIt=char *,
            Char=wchar_t,
            Iterator=char *,
            InputIt=wchar_t *
        ]
fmt\format.h(1550): note: see reference to function template instantiation 'Iterator *fmt::v6::detail::format_decimal<Char,UInt,char*>(Iterator,UInt,int)' being compiled
        with
        [
            Iterator=char *,
            Char=wchar_t,
            UInt=uint_type
        ]

@vitaut
Copy link
Contributor

vitaut commented Jun 3, 2020

What library version do you use?

@TheQwertiest
Copy link
Contributor Author

I used the latest HEAD available at the time of the posting.

@vitaut
Copy link
Contributor

vitaut commented Jun 3, 2020

What's the commit hash?

@TheQwertiest
Copy link
Contributor Author

TheQwertiest commented Jun 3, 2020

The latest 16aec06 also has this issue (have tried just now).
Full commit hash: 16aec06

@vitaut
Copy link
Contributor

vitaut commented Jun 4, 2020

Fixed in 21409cf. Thanks for reporting.

@vitaut vitaut closed this as completed Jun 4, 2020
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

No branches or pull requests

2 participants