-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Closed
Description
Description
When i compile the following code with the 3.12.0 it will throw an exception, compiled with the 3.11.1 the expected result will be print out.
Is this a bug in 3.12.0 or is this a misuse of the API from my side?
Reproduction steps
Compiled with:
clang++ t1.cpp -o t1
Expected vs. actual results
The expected result is:
t2=3
With 3.12.0 i see this instead:
Exception: [json.exception.type_error.303] incompatible ReferenceType for get_ref, actual type is number
Minimal code example
//#include "json-3.12.0.hpp"
#include "json-3.11.1.hpp"
#include <iostream>
using Json = nlohmann::basic_json<>;
int main() try
{
const Json test_js = Json::parse(R"({ "t2":3 })");
if(const auto iter{test_js.find("t2")}; iter != test_js.end())
{
auto ref = iter->get_ref<const Json::number_integer_t&>();
std::cout << "t2=" << ref << '\n';
}
else
{
std::cerr << "Can't find 't2'\n";
}
return 0;
}
catch(const std::exception& e)
{
std::cerr << "Exception: " << e.what() << '\n';
}
Error messages
Compiler and operating system
Linux Manjaro, clang 20.1.6 (Manjaro Repo), g++ 15.1.1 (Manjaro Repo)
Library version
3.11.1 and 3.12.0 both as single header version
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.
Metadata
Metadata
Assignees
Labels
No labels