FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[BUG] to_string(...) hidden by to_string(std::any) overload · Issue #200 · hsutter/cppfront · GitHub

Repository navigation

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

Description

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";
}
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

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions


      Back | FazBrowse Home | New Git URL