While debugging an application I came up with the following example:
#include <nlohmann/json.hpp>
using nlohmann::json;
struct X {
X(const std::string& s){}
};
int main() {
X x("{}"_json); // why compiler allows this?
}
See at Godbolt
Could someone explain this? Is this a bug or an unexpected side effect of nlohmann/json library?
Update:
... and here is the second question:
As implicit to_string conversion is a documented feature, then is this a bug that this even simpler example fails at runtime?
#include <nlohmann/json.hpp>
using nlohmann::json;
int main() {
std::string j = "{}"_json;
}
terminate called after throwing an instance of 'nlohmann::json_abi_v3_11_2::detail::type_error' what(): [json.exception.type_error.302] type must be string, but is object