You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve error message when trying to format wide into narrow string #117
#include<string>
#include<fmt/format.h>intmain()
{
auto s1 = fmt::format("format with parameter {}", "string");
auto s2 = fmt::format("format with parameter {}", L"wstring");
}
with VS 2013 Update 4 gives the following error:
1>fmt/format.h(724): error C2248: 'fmt::internal::CharTraits<char>::convert' : cannot access private member declared in class 'fmt::internal::CharTraits<char>'
1> fmt/format.h(457) : see declaration of 'fmt::internal::CharTraits<char>::convert'
1> fmt/format.h(454) : see declaration of 'fmt::internal::CharTraits<char>'
1> fmt/format.h(723) : while compiling class template member function ‘void fmt::internal::MakeValue<char>::set_string(fmt::WStringRef)'
1> fmt/format.h(800) : see reference to function template instantiation 'void fmt::internal::MakeValue<char>::set_string(fmt::WStringRef)' being compiled
1> fmt/format.h(2485) : see reference to class template instantiation 'fmt::internal::MakeValue<char>' being compiled
1> Test.cpp(6) : see reference to function template instantiation 'std::string fmt::format<const char[7]>(fmt::StringRef,const char (&)[7])' being compiled
which is rather confusing because the error points to the first format statement, not the second. This is due to a low quality of MSVC diagnostics as both GCC and Clang point exactly to the source of error, but would be nice to do something about it anyway.
Make MakeValue ctors taking wide strings private with enable_if or similar if Char is char. This will require having two wide string ctors, one private and one public.
Generate an error in MakeValue ctor taking wide string when Char is char.
Activity
vitaut commentedon Feb 24, 2015
Oh my, MSVC is horrible.
vitaut commentedon Feb 24, 2015
There are at least two options:
MakeValuectors taking wide strings private withenable_ifor similar ifCharischar. This will require having two wide string ctors, one private and one public.MakeValuector taking wide string whenCharischar.vitaut commentedon Feb 25, 2015
Another thing to consider is that
MakeValue's ctors should accept (or forbid) anything convertible to wide strings.vitaut commentedon Feb 25, 2015
Fixed in f014d32.
vitaut commentedon Feb 25, 2015
Check if the same needs to be done for wide chars.
vitaut commentedon Feb 25, 2015
Yes, it does.
vitaut commentedon Feb 26, 2015
wchar_t is done in ed49014, but need to check writers as well.
vitaut commentedon Feb 26, 2015
Fixed for writers too.