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

Visual Studio 22 (17.2.3) + Module compilation results in ambiguous format_to call #2920

Closed
Agga opened this issue Jun 1, 2022 · 6 comments

Comments

@Agga
Copy link
Contributor

Agga commented Jun 1, 2022

Setup

# CMakeLists.txt

set(FMT_CAN_MODULE OFF)
if (CMAKE_CXX_STANDARD GREATER 17 AND
    # msvc 16.10-pre4
    MSVC AND CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 19.29.30035)
  set(FMT_CAN_MODULE ON) # << this is a modification from me to get module compilation going
endif ()

cmake -DCMAKE_CXX_STANDARD=20 -DFMT_MODULE=ON

Bug

The format_to call in os.cc function format_windows_error becomes ambiguous.

fmt/src/os.cc

Line 172 in 9d60395

format_to(buffer_appender<char>(out), "{}: {}", message, utf8_message);

2>fmt.cc
2>D:\projects\fmt-master\src\os.cc(172,78): error C2668: 'fmt::v8::format_to': ambiguous call to overloaded function
2>D:\projects\fmt-master\include\fmt\core.h(3139,17): message : could be 'OutputIt fmt::v8::format_to<fmt::v8::appender,const char*&,fmt::v8::detail::utf16_to_utf8&,0>(OutputIt,fmt::v8::basic_format_string<char,const char *&,fmt::v8::detail::utf16_to_utf8 &>,const char *&,fmt::v8::detail::utf16_to_utf8 &)'
2>        with
2>        [
2>            OutputIt=fmt::v8::appender
2>        ]
2>C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Tools\MSVC\14.32.31326\include\format(3046,11): message : or       '_OutputIt std::format_to<fmt::v8::appender,const char*&,fmt::v8::detail::utf16_to_utf8&>(_OutputIt,const std::_Basic_format_string<char,const char *&,fmt::v8::detail::utf16_to_utf8 &>,const char *&,fmt::v8::detail::utf16_to_utf8 &)' [found using argument-dependent lookup]
2>        with
2>        [
2>            _OutputIt=fmt::v8::appender
2>        ]
2>D:\projects\fmt-master\src\os.cc(172,78): message : while trying to match the argument list '(fmt::v8::appender, const char [7], const char *, fmt::v8::detail::utf16_to_utf8)'
2>Generating Code...
2>Done building project "fmt.vcxproj" -- FAILED.
========== Build: 1 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Possible Explanation

fmt.cc includes <chrono> which pulls in <format>. Which turns this https://en.cppreference.com/w/cpp/utility/format/format_to into a valid candidate and makes the call ambiguous.

@vitaut
Copy link
Contributor

vitaut commented Jun 1, 2022

Please post the complete error message.

@Agga
Copy link
Contributor Author

Agga commented Jun 1, 2022

added error message

@vitaut
Copy link
Contributor

vitaut commented Jun 1, 2022

Looks like a bug in MSVC: std::format_to shouldn't be discoverable via ADL because none of the arguments are in the std namespace. Please report to Microsoft.

@mwinterb
Copy link
Contributor

mwinterb commented Jun 1, 2022

Does this issue not reduce down to this since the base class of appender is std::back_insert_iterator? https://gcc.godbolt.org/z/EWaG3G7GG

@Agga
Copy link
Contributor Author

Agga commented Jun 1, 2022

buffer_appender<char>(out)

I think this is actually a std::back_inserter object - that should pull std::format_to into the lookup resolution?

class appender : public std::back_insert_iterator<detail::buffer<char>> {

using buffer_appender = conditional_t<std::is_same<T, char>::value, appender,

@vitaut
Copy link
Contributor

vitaut commented Jun 1, 2022

Ah, good catch. In that case we should namespace qualify the call to format_to, i.e. change it to fmt::format_to. A PR is welcome!

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