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

Improve error message when trying to format wide into narrow string #117

Closed
vitaut opened this issue Feb 20, 2015 · 8 comments
Closed

Improve error message when trying to format wide into narrow string #117

vitaut opened this issue Feb 20, 2015 · 8 comments

Comments

@vitaut
Copy link
Contributor

vitaut commented Feb 20, 2015

Compiling the code

#include <string>
#include <fmt/format.h>

int main()
   {
   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.

@vitaut
Copy link
Contributor Author

vitaut commented Feb 24, 2015

Oh my, MSVC is horrible.

@vitaut
Copy link
Contributor Author

vitaut commented Feb 24, 2015

There are at least two options:

  1. 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.
  2. Generate an error in MakeValue ctor taking wide string when Char is char.

@vitaut
Copy link
Contributor Author

vitaut commented Feb 25, 2015

Another thing to consider is that MakeValue's ctors should accept (or forbid) anything convertible to wide strings.

@vitaut
Copy link
Contributor Author

vitaut commented Feb 25, 2015

Fixed in f014d32.

@vitaut vitaut closed this as completed Feb 25, 2015
@vitaut
Copy link
Contributor Author

vitaut commented Feb 25, 2015

Check if the same needs to be done for wide chars.

@vitaut vitaut reopened this Feb 25, 2015
@vitaut
Copy link
Contributor Author

vitaut commented Feb 25, 2015

Yes, it does.

@vitaut
Copy link
Contributor Author

vitaut commented Feb 26, 2015

wchar_t is done in ed49014, but need to check writers as well.

@vitaut
Copy link
Contributor Author

vitaut commented Feb 26, 2015

Fixed for writers too.

@vitaut vitaut closed this as completed Feb 26, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant