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

Windows warning C4244 in fmt/chrono.h #1649

Closed
Tradias opened this issue Apr 27, 2020 · 3 comments
Closed

Windows warning C4244 in fmt/chrono.h #1649

Tradias opened this issue Apr 27, 2020 · 3 comments

Comments

@Tradias
Copy link

Tradias commented Apr 27, 2020

Compiling the following on Windows:

#include <fmt/chrono.h>

int main()
{
    auto s = fmt::format("{}", std::chrono::seconds(1));
    return 0;
}

using

Microsoft (R) C/C++ Optimizing Compiler Version 19.25.28614 for x64
Windows 10 SDK (10.0.18362.0)
fmt v6.2.0

and compiler flags: /W1 -DFMT_LOCALE

produces the warning:

[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xutility(3606): warning C4244: 'argument': conversion from 'const wchar_t' to 'const char', possible loss of data
[build] C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\include\xutility(3643): note: see reference to function template instantiation '_OutIt std::_Copy_unchecked<_InIt,_OutIt>(_InIt,_InIt,_OutIt)' being compiled
[build]         with
[build]         [
[build]             _OutIt=std::back_insert_iterator<fmt::v6::basic_memory_buffer<char,500,std::allocator<char>>>,
[build]             _InIt=const wchar_t *
[build]         ]
[build] ...\fmt\include\fmt/chrono.h(778): note: see reference to function template instantiation '_OutIt std::copy<const wchar_t*,OutputIt>(_InIt,_InIt,_OutIt)' being compiled
[build]         with
[build]         [
[build]             _OutIt=std::back_insert_iterator<fmt::v6::basic_memory_buffer<char,500,std::allocator<char>>>,
[build]             OutputIt=std::back_insert_iterator<fmt::v6::basic_memory_buffer<char,500,std::allocator<char>>>,
[build]             _InIt=const wchar_t *
[build]         ]
[build] ...\fmt\include\fmt/chrono.h(1105): note: see reference to function template instantiation 'OutputIt fmt::v6::internal::format_duration_unit<Char,Period,std::back_insert_iterator<fmt::v6::basic_memory_buffer<char,500,std::allocator<char>>>>(OutputIt)' being compiled
[build]         with
[build]         [
[build]             OutputIt=std::back_insert_iterator<fmt::v6::basic_memory_buffer<char,500,std::allocator<char>>>,
[build]             Char=char,
[build]             Period=std::ratio<1,1>
[build]         ]
[build] ...\fmt\include\fmt\core.h(898): note: see reference to function template instantiation 'std::back_insert_iterator<fmt::v6::internal::buffer<char>> fmt::v6::formatter<Arg,char,void>::format<Context>(const std::chrono::duration<__int64,std::ratio<1,1>> &,FormatContext &)' being compiled
[build]         with
[build]         [
[build]             Arg=std::chrono::duration<__int64,std::ratio<1,1>>,
[build]             Context=fmt::v6::format_context,
[build]             FormatContext=fmt::v6::format_context
[build]         ]
[build] ...\fmt\include\fmt\core.h(898): note: see reference to function template instantiation 'std::back_insert_iterator<fmt::v6::internal::buffer<char>> fmt::v6::formatter<Arg,char,void>::format<Context>(const std::chrono::duration<__int64,std::ratio<1,1>> &,FormatContext &)' being compiled
[build]         with
[build]         [
[build]             Arg=std::chrono::duration<__int64,std::ratio<1,1>>,
[build]             Context=fmt::v6::format_context,
[build]             FormatContext=fmt::v6::format_context
[build]         ]
[build] ...\fmt\include\fmt\core.h(885): note: see reference to function template instantiation 'void fmt::v6::internal::value<Context>::format_custom_arg<T,fmt::v6::formatter<T,char,void>>(const void *,fmt::v6::basic_format_parse_context<char,fmt::v6::internal::error_handler> &,Context &)' being compiled
[build]         with
[build]         [
[build]             Context=fmt::v6::format_context,
[build]             T=std::chrono::duration<__int64,std::ratio<1,1>>
[build]         ]
[build] ...\fmt\include\fmt\core.h(882): note: see reference to function template instantiation 'void fmt::v6::internal::value<Context>::format_custom_arg<T,fmt::v6::formatter<T,char,void>>(const void *,fmt::v6::basic_format_parse_context<char,fmt::v6::internal::error_handler> &,Context &)' being compiled
[build]         with
[build]         [
[build]             Context=fmt::v6::format_context,
[build]             T=std::chrono::duration<__int64,std::ratio<1,1>>
[build]         ]
[build] ...\fmt\include\fmt\core.h(1213): note: see reference to function template instantiation 'fmt::v6::internal::value<Context>::value<T>(const T &)' being compiled
[build]         with
[build]         [
[build]             Context=fmt::v6::format_context,
[build]             T=std::chrono::duration<__int64,std::ratio<1,1>>
[build]         ]
[build] ...\fmt\include\fmt\core.h(1213): note: see reference to function template instantiation 'fmt::v6::internal::value<Context>::value<T>(const T &)' being compiled
[build]         with
[build]         [
[build]             Context=fmt::v6::format_context,
[build]             T=std::chrono::duration<__int64,std::ratio<1,1>>
[build]         ]
[build] ...\fmt\include\fmt\core.h(1344): note: see reference to function template instantiation 'fmt::v6::internal::value<Context> fmt::v6::internal::make_arg<true,Context,std::chrono::duration<__int64,std::ratio<1,1>>,0>(const T &)' being compiled
[build]         with
[build]         [
[build]             Context=fmt::v6::format_context,
[build]             T=std::chrono::duration<__int64,std::ratio<1,1>>
[build]         ]
[build] ...\fmt\include\fmt\core.h(1344): note: while compiling class template member function 'fmt::v6::format_arg_store<fmt::v6::basic_format_context<std::back_insert_iterator<fmt::v6::internal::buffer<char>>,char>,std::chrono::duration<__int64,std::ratio<1,1>>>::format_arg_store(const std::chrono::duration<__int64,std::ratio<1,1>> &)'
[build] ...\fmt\include\fmt\core.h(1649): note: see reference to function template instantiation 'fmt::v6::format_arg_store<fmt::v6::basic_format_context<std::back_insert_iterator<fmt::v6::internal::buffer<char>>,char>,std::chrono::duration<__int64,std::ratio<1,1>>>::format_arg_store(const std::chrono::duration<__int64,std::ratio<1,1>> &)' being compiled
[build] ...\fmt\include\fmt\core.h(1737): note: see reference to class template instantiation 'fmt::v6::format_arg_store<fmt::v6::basic_format_context<std::back_insert_iterator<fmt::v6::internal::buffer<char>>,char>,std::chrono::duration<__int64,std::ratio<1,1>>>' being compiled
[build] ..\src\main.cpp(13): note: see reference to function template instantiation 'std::basic_string<char,std::char_traits<char>,std::allocator<char>> fmt::v6::format<char[3],std::chrono::seconds,char>(const S (&),std::chrono::seconds &&)' being compiled
[build]         with
[build]         [
[build]             S=char [3]
[build]         ]
vitaut added a commit that referenced this issue Apr 28, 2020
vitaut added a commit that referenced this issue Apr 28, 2020
@vitaut
Copy link
Contributor

vitaut commented Apr 28, 2020

Fixed in f2ed03b.

@vitaut vitaut closed this as completed Apr 28, 2020
@Tradias
Copy link
Author

Tradias commented Apr 28, 2020

Cool thanks, I wonder how it didn't work correctly before. According to the log the type of Char in the format_duration_unit function is char yet the condition:

if (const_check(std::is_same<Char, wchar_t>()))

evaluated to true.

@vitaut
Copy link
Contributor

vitaut commented Apr 29, 2020

AFAICS it is evaluated to false: https://godbolt.org/z/XR3fXD. In any case it's gone now.

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