Skip to content

Precedence of to_json and builtin harmful #1617

Description

@ingo-loehken

For a class that supports user-defined conversion to a const char* (compatible to string_type of nlohmann::json) and a to_json specialization, the expectation would be that the to_json function takes precedence.

class MyClass
{
public:
	operator const char*() const; // (1)
	template <typename jsonT, typename T> friend inline typename std::enable_if_t<std::is_same_v<MyClass,std::remove_const_t<std::remove_reference_t<T>>>> to_json(jsonT&, T&&); // (2)
};

nlohmann::json x{MyClass{}}; // (3)

Executing (3), I would expect that (2) is selected, but (1) takes precedence.

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

    kind: bugstate: stalethe issue has not been updated in a while and will be closed automatically soon unless it is updated

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions