Skip to content

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

Closed

Description

@vitaut

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.

Activity

  1. vitaut commented on Feb 24, 2015

    @vitaut
    ContributorAuthor

    Oh my, MSVC is horrible.

  2. vitaut commented on Feb 24, 2015

    @vitaut
    ContributorAuthor

    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.
  3. vitaut commented on Feb 25, 2015

    @vitaut
    ContributorAuthor

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

  4. vitaut commented on Feb 25, 2015

    @vitaut
    ContributorAuthor

    Fixed in f014d32.

  5. vitaut commented on Feb 25, 2015

    @vitaut
    ContributorAuthor

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

  6. reopened this on Feb 25, 2015
  7. vitaut commented on Feb 25, 2015

    @vitaut
    ContributorAuthor

    Yes, it does.

  8. vitaut commented on Feb 26, 2015

    @vitaut
    ContributorAuthor

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

  9. vitaut commented on Feb 26, 2015

    @vitaut
    ContributorAuthor

    Fixed for writers too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions