From fb9a2643c8354b4e436c305378e53a1f6b591a66 Mon Sep 17 00:00:00 2001 From: Anthony Van Herrewege Date: Wed, 30 Oct 2019 15:46:31 +0100 Subject: [PATCH] Add test for #1647. --- test/src/unit-conversions.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/src/unit-conversions.cpp b/test/src/unit-conversions.cpp index 9d48e29d..1a5033df 100644 --- a/test/src/unit-conversions.cpp +++ b/test/src/unit-conversions.cpp @@ -1537,6 +1537,31 @@ NLOHMANN_JSON_SERIALIZE_ENUM(TaskState, {TS_COMPLETED, "completed"}, }) +namespace +{ +// Helper struct to test whether compile error does not trigger upon +// conversion of an enum in the presence of non-member operator== for +// user-defined type with "non default" from_json function (#1647). +struct NonDefaultFromJsonStruct { }; + +inline bool operator== (NonDefaultFromJsonStruct const& lhs, NonDefaultFromJsonStruct const& rhs) +{ + return true; +} +} + +namespace nlohmann +{ +template <> +struct adl_serializer +{ + static NonDefaultFromJsonStruct from_json (json const& j) + { + return {}; + } +}; +} + TEST_CASE("JSON to enum mapping") { SECTION("enum class")