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

join couldn't be found an appropriate overload when fmt is imported as a module. #4190

Open
LeenHawk opened this issue Oct 5, 2024 · 2 comments · May be fixed by #4239
Open

join couldn't be found an appropriate overload when fmt is imported as a module. #4190

LeenHawk opened this issue Oct 5, 2024 · 2 comments · May be fixed by #4239

Comments

@LeenHawk
Copy link

LeenHawk commented Oct 5, 2024

The compiler is failing to find an appropriate overload for the fmt::join function that works with std::vector<int> or other
std::vector<xxx>.

Environment:

  1. MSVC 17.0
  2. CMake 3.30.2
  3. ninja 1.11.1

Error message:

C:\Users\leenhawk\Workspace\stamp2\main.cpp(137): error C2672: 'fmt::v11::join': no matching overloaded function found
C:\Users\leenhawk\Workspace\stamp2\cmake-build-debug\_deps\fmt-src\include\fmt\xchar.h(157): note: it could be 'fmt::v11::tuple_join_view<wchar_t,T...> fmt::v11::join(const std::tuple<_Types...> &,fmt::v11::basic_string_view<wchar_t>)'
C:\Users\leenhawk\Workspace\stamp2\main.cpp(137): note: 'fmt::v11::tuple_join_view<wchar_t,T...> fmt::v11::join(const std::tuple<_Types...> &,fmt::v11::basic_string_view<wchar_t>)': cannot deduce 'const std::tuple<_Types...> &' from 'const std::vector<std::string,std::allocator<std::string>>'
C:\Users\leenhawk\Workspace\stamp2\cmake-build-debug\_deps\fmt-src\include\fmt\xchar.h(151): note: or 'fmt::v11::join_view<const T*,const T*,wchar_t> fmt::v11::join(std::initializer_list<_Elem>,fmt::v11::basic_string_view<wchar_t>)'
C:\Users\leenhawk\Workspace\stamp2\main.cpp(137): note: 'fmt::v11::join_view<const T*,const T*,wchar_t> fmt::v11::join(std::initializer_list<_Elem>,fmt::v11::basic_string_view<wchar_t>)': cannot deduce 'std::initializer_list<_Elem>' from 'const std::vector<std::string,std::allocator<std::string>>'
C:\Users\leenhawk\Workspace\stamp2\cmake-build-debug\_deps\fmt-src\include\fmt\xchar.h(144): note: or 'fmt::v11::join_view<unknown-type,unknown-type,wchar_t> fmt::v11::join(Range &&,fmt::v11::basic_string_view<wchar_t>)'
C:\Users\leenhawk\Workspace\stamp2\main.cpp(137): note: 'initialization': cannot convert 'const char [3]' to 'fmt::v11::basic_string_view<wchar_t>'
C:\Users\leenhawk\Workspace\stamp2\main.cpp(137): note: 'fmt::v11::basic_string_view<wchar_t>::basic_string_view': no overloaded function can convert all argument types
C:\Users\leenhawk\Workspace\stamp2\cmake-build-debug\_deps\fmt-src\include\fmt\base.h(521): note: it could be 'fmt::v11::basic_string_view<wchar_t>::basic_string_view(const Char *)'
        with
        [
            Char=wchar_t
        ]
C:\Users\leenhawk\Workspace\stamp2\main.cpp(137): note: 'fmt::v11::basic_string_view<wchar_t>::basic_string_view(const Char *)': cannot convert argument 1 from 'const char [3]' to 'const Char *'
        with
        [
            Char=wchar_t
        ]
C:\Users\leenhawk\Workspace\stamp2\main.cpp(137): note: types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

The minimal reproducal example:

CMakeLists.txt

cmake_minimum_required(VERSION 3.30 FATAL_ERROR)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_EXPERIMENTAL_CXX_IMPORT_STD "0e5b6991-d74f-4b3d-a41c-cf096e0b2508")
set(CMAKE_CXX_MODULE_STD 1)

project(main LANGUAGES CXX)

add_executable(main main.cpp)

include(FetchContent)
FetchContent_Declare(
        fmt
        GIT_REPOSITORY https://github.com/fmtlib/fmt
        GIT_TAG        0c9fce2ffefecfdce794e1859584e25877b7b592) # 11.0.2
FetchContent_MakeAvailable(fmt)
#target_link_libraries(main fmt::fmt)
target_sources(main
        PUBLIC FILE_SET CXX_MODULES
        FILES
        ${fmt_SOURCE_DIR}/src/fmt.cc
)
target_include_directories(main PRIVATE ${fmt_SOURCE_DIR}/include)

main.cpp

import fmt;
import std;
int main(int argc, char* argv[])
{
    auto v = std::vector<int>{1, 2, 3};
    fmt::print("{}", fmt::join(v, ", "));
    return 0;
}
@LeenHawk
Copy link
Author

LeenHawk commented Oct 5, 2024

There is a example working correctly in goltbot with#include:

#include <fmt/ranges.h>
#include <vector>
#include <string>
int main() {
  auto v = std::vector<std::string>{"1", "2", "3"};
    fmt::print("{}", fmt::join(v, ", "));
}

@vitaut
Copy link
Contributor

vitaut commented Oct 5, 2024

Looks like this overload of join is currently not marked as exported:

auto join(Range&& r, string_view sep)

A PR to fix it would be welcome.

@Arghnews Arghnews linked a pull request Nov 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants