pboettch / json-schema-validator

JSON schema validator for JSON for Modern C++
Other
466 stars 134 forks source link

Error compiling on windows operator= is ambiguous #134

Closed elmajime closed 3 years ago

elmajime commented 3 years ago

https://github.com/pboettch/json-schema-validator/blob/1519c845c2b1bbf35021feb11c23625de603ca1e/src/json-validator.cpp#L730

Might be changed to: patternString_ = attr.value().get<std::string>();

to avoid compilation error: Error C2593: 'operator =' is ambiguous nlohmann_json_schema_validator

The problem is present on version tagged 2.1.0 as well but on line 666.

pboettch commented 3 years ago

What version of Visual Studio are you using?

pboettch commented 3 years ago

And which version of nlohmann::json?

elmajime commented 3 years ago

Nlohmann version 3.7.1 and Visual studio 2019

pboettch commented 3 years ago

And if you do a simple example only using nlohmann json and do std::string s = json_var.value(), does this work in your environment?

pboettch commented 3 years ago

Does the compiler tell why it is ambiguous?

elmajime commented 3 years ago

I don't have the time to test right now but will do as soon as possible. But I also wanted to point out that I had to change the base CMakeLists.txt in order for Visual Studio to be able to compile the library nlohmann_json_schema_validator. The problem was that the project name and the target name where the same, this resulted in MSVC solution to contain all but the nlohmann_json_schema_validator target.

In the end I renamed the library target to lib_nlohmann_json_schema_validator so it's different from the project name and change the name of the output back to nlohmann_json_schema_validator like so:

<in the set_target_properties part> OUTPUT_NAME "nlohmann_json_schema_validator"

On the ambiguous error: it seems the compiler can't decide on which basic_string constructor to use. But that's what the Clang plugin tells me.

elmajime commented 3 years ago

I've just tried this and got the same result:

nlohmann::json json_var = {
                  {"pi", 3.141},
                  {"happy", true},
                  {"name", "Niels"},
                  {"nothing", nullptr},
                  {"answer", {
                    {"everything", 42}
                  }},
                  {"list", {1, 0, 2}},
                  {"object", {
                    {"currency", "USD"},
                    {"value", 42.99}
                  }}
                };

std::string s = json_var.value();
pboettch commented 3 years ago

It's a problem of the compiler version. Could you try the latest version of nlohmann::json?

elmajime commented 3 years ago

Ok, just tried with the latest version of Nlohmann Json : 3.9.1 and it works. I removed the hotfix I originaly made.

On another note: I had to change the CMakeLists.txt in order to have both Debug and Release versions of the library generated (with a suffix for the debug) in order to link correctly in static on Windows. I did that by adding DEBUG_POSTFIX d to the properties of the target. I thought you might want to know.

Thanks again for your help !