Skip to content

[BUG] to_string(...) hidden by to_string(std::any) overload #200

Closed
@filipsajdak

Description

@filipsajdak

Having the code

struct X {};

main: () -> int = {
    x: X = ();

    std::cout << "x  = '(x)$'" << std::endl;
}

Expected

Output:

../tests/bug_cast_to_optional.cpp2... ok (mixed Cpp1/Cpp2, Cpp2 code passes safety checks)

x  = '(customize me - no cpp2::to_string overload exists for this type)'

Actual

../tests/bug.cpp2... ok (mixed Cpp1/Cpp2, Cpp2 code passes safety checks)

x  = 'std::any'

Cause

The X type matches:

inline auto to_string(std::any const&) -> std::string {
  return "std::any";
}

Possible fix

Replace the above overload to:

template<typename T>
    requires std::is_same_v<T, std::any>
inline auto to_string(T const&) -> std::string {
  return "std::any";
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions