Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Regression: no matching literal operator for call to 'operator""_json' #3645

Closed
2 tasks done
nlohmann opened this issue Aug 1, 2022 · 7 comments · Fixed by #3646
Closed
2 tasks done

Regression: no matching literal operator for call to 'operator""_json' #3645

nlohmann opened this issue Aug 1, 2022 · 7 comments · Fixed by #3646
Assignees
Labels
confirmed kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@nlohmann
Copy link
Owner

nlohmann commented Aug 1, 2022

Description

Code I wrote for #3594 does no longer compile with the latest 3.11.0 release.

The line in question is

json j;
j = R"({ "1": 1, "2": [ 1, 2, 3, 4, 5], "3": "third-value", "4": { "4-1": 1, "4-2": 2 }, "5": true })"_json;

This compiled before, but now fails with

example.cpp:261:107: error: no matching literal operator for call to 'operator""_json' with arguments of types 'const char *' and 'unsigned long', and no matching literal operator template
    j = R"({ "1": 1, "2": [ 1, 2, 3, 4, 5], "3": "third-value", "4": { "4-1": 1, "4-2": 2 }, "5": true })"_json;
                                                                                                          ^

Reproduction steps

Compile

#include <nlohmann/json.hpp>

using json = nlohmann::json;

int main() {
    json j;
    j = R"({ "1": 1, "2": [ 1, 2, 3, 4, 5], "3": "third-value", "4": { "4-1": 1, "4-2": 2 }, "5": true })"_json;
}

with version 3.11.0.

Expected vs. actual results

Expected: compiles without error.

Actual: Error.

Minimal code example

See above.

Error messages

example.cpp:7:107: error: no matching literal operator for call to 'operator""_json' with arguments of types 'const char *' and 'unsigned long', and no matching literal operator template
    j = R"({ "1": 1, "2": [ 1, 2, 3, 4, 5], "3": "third-value", "4": { "4-1": 1, "4-2": 2 }, "5": true })"_json;
                                                                                                          ^

Compiler and operating system

Apple Clang 13.1.6 (clang-1316.0.21.2.5), macOS 12.4 (21F79)

Library version

3.11.0 release version

Validation

@falbrechtskirchinger
Copy link
Contributor

Dang it. You know what helps in finding these issues? Remembering to add the CI target to the workflow. :-(

@nlohmann
Copy link
Owner Author

nlohmann commented Aug 1, 2022

I guess there will be a 3.11.1 then :)

@falbrechtskirchinger
Copy link
Contributor

Guess so. Working on a fix.

@nlohmann
Copy link
Owner Author

nlohmann commented Aug 1, 2022

I was a bit confused that all tests had the namespace for the literals included.

@falbrechtskirchinger
Copy link
Contributor

I'm modifying the tests and then I'm going to break it again on purpose. The first PR test run should fail.

@nlohmann
Copy link
Owner Author

nlohmann commented Aug 1, 2022

I can confirm adding

using namespace nlohmann::json_literals;

fixes the error.

@nlohmann
Copy link
Owner Author

nlohmann commented Aug 1, 2022

I can confirm that #3646 fixes this issue.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants