Skip to content

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

Description

@Agga

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions