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

Ambiguous call to overloaded function arg_mapper when xchars header is included #2465

Closed
odygrd opened this issue Aug 24, 2021 · 7 comments
Closed

Comments

@odygrd
Copy link

odygrd commented Aug 24, 2021

After upgrading to fmt v8.0.1 I am getting a compilation error on visual studio.
I haven't really looked in depth but it looks like it is coming from lib fmt.
It only happens for specific versions of visual studio and not for every version it seems.

It is reproduced here :
https://github.com/odygrd/quill/runs/3413814682?check_suite_focus=true

I could also reproduce it myself on Visual Studio 2019 16.8.1

Screenshot 2021-08-24 at 20 44 13

Anyone has seen this before on windows ? I can compile fine on macos and on linux

It looks like one of the tests that is using fmt causes this compiler error since the workflow where the tests are no being compiled compiles fine. I am still trying to dig deeper and find exactly where it is caused

@odygrd odygrd changed the title Potential visual studio 2019 16.8.1 compilation error Potential visual studio 2019 16.8.1 compilation error - Ambigious call to overloaded function arg_mapper Aug 24, 2021
@vitaut
Copy link
Contributor

vitaut commented Aug 24, 2021

It looks like you are mixing wide and narrow character strings which is not supported:

fmt::v8::detail::arg_mapper<fmt::v8::basic_format_context<fmt::v8::appender,char>>::map<_Iter>(T)' [D:\a\quill\build\quill\test\TEST_Log.vcxproj]
          with
          [
              _Iter=const wchar_t *,
              T=const wchar_t *
          ]

Notice that the basic_format_context<..., char> is narrow (char) while T is wide (const wchar_t *).

@odygrd
Copy link
Author

odygrd commented Aug 24, 2021

It seems that including xchars.h makes the function ambigious.
The code below worked in previous version. In this version it fails to compile because xchars.h is included.
If you comment out #include <fmt/xchar.h> the code compiles

https://godbolt.org/z/3T6E1fsGa

@odygrd odygrd changed the title Potential visual studio 2019 16.8.1 compilation error - Ambigious call to overloaded function arg_mapper Ambiguous call to overloaded function arg_mapper when xchars header is included Aug 24, 2021
@Brainy0207
Copy link
Contributor

Brainy0207 commented Aug 25, 2021

https://godbolt.org/z/3T6E1fsGa

But you are still mixing wide and single byte characters:
grafik

@odygrd
Copy link
Author

odygrd commented Aug 25, 2021

I checked and see it works for LOG(L"test", arg_1);

Prior to 8.0.1 and without including xchars.h it was possible to use a non-wide char format string with wide char arguments. The only requirement was not to mix non-wide with wide arguments.

When importing xchars.h tho it looks like this is not the case anymore and that a wide char argument also requires a wide char format string.

Is that expected behaviour ?

@Brainy0207
Copy link
Contributor

#include <fmt/format.h>

int main()
{
    const wchar_t* arg_1 = L"Hello?";
    fmt::format(FMT_STRING("{}"), arg_1);
    return 0;
}

without including xchar.h, 7.1.3 and 8.0.1 (trunk) give me:
grafik

@odygrd
Copy link
Author

odygrd commented Aug 25, 2021

Thanks for the response. I am referring to the above code specifically when using check_format_string

Another example (with xchars header included)

works with wstring and non wide string format
https://godbolt.org/z/jjE71KjoY

does not work anymore if you change wstring to wchar_t
https://godbolt.org/z/3T6E1fsGa

@vitaut
Copy link
Contributor

vitaut commented Aug 27, 2021

Fixed in 6d597e3. Now it gives the expected error (since mixing of narrow and wide strings is disallowed) regardless of whether xchar.h is included or not:

include/fmt/core.h:2481:12: error: call to deleted constructor of 'conditional_t<has_formatter<mapped_type, context>::value, formatter<mapped_type>, fallback_formatter<const wchar_t *>>' (aka 'fmt::v8::detail::fallback_formatter<const wchar_t *>')
  auto f = conditional_t<has_formatter<mapped_type, context>::value,
           ^
include/fmt/core.h:2727:23: note: in instantiation of function template specialization 'fmt::v8::detail::parse_format_specs<const wchar_t *, fmt::v8::detail::compile_parse_context<char>>' requested here
        parse_funcs_{&parse_format_specs<Args, parse_context_type>...} {}
                      ^
include/fmt/core.h:2768:37: note: in instantiation of member function 'fmt::v8::detail::format_string_checker<char, fmt::v8::detail::error_handler, const wchar_t *>::format_string_checker' requested here
      (parse_format_string<true>(s, checker(s, {})), true);
                                    ^
test1.cc:8:16: note: in instantiation of function template specialization 'fmt::v8::detail::check_format_string<const wchar_t *, FMT_COMPILE_STRING, 0>' requested here
  fmt::detail::check_format_string<std::remove_reference_t<Args>...>(
               ^
test1.cc:28:3: note: in instantiation of function template specialization 'log<FMT_COMPILE_STRING, const wchar_t *&>' requested here
  LOG("test", arg_1);
  ^
test1.cc:23:5: note: expanded from macro 'LOG'
    log(FMT_STRING(fmt), ##__VA_ARGS__); \
    ^
include/fmt/core.h:979:3: note: 'fallback_formatter' has been explicitly marked deleted here
  fallback_formatter() = delete;
  ^

Thanks for reporting!

@vitaut vitaut closed this as completed Aug 27, 2021
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

3 participants