-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Description
Description
Compilation fails when "JSON_Diagnostic_Positions" cmake option is turned ON.
I think it is a minor bug, I am able to fix it by using the start_pos() and end_pos() public functions instead of using private member variables as shown in the attached patch.
fix_patch.txt
Please review and let me know if this is correct fix, I will raise a PR shortly.
Reproduction steps
- Turn on the cmake option in CMakelists.txt; "option(JSON_Diagnostic_Positions "Enable diagnostic positions." ON)"
- mkdir build
- cd build
- cmake .. DBUILD_TESTING=ON
- cmake --build .
Step 5 fails****
Expected vs. actual results
Expected result:
Build succeeded
Actual result:
/home/hnampall/json/include/nlohmann/json.hpp: In instantiation of ‘nlohmann::json_abi_diag_dp_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::basic_json(const BasicJsonType&) [with BasicJsonType = nlohmann::json_abi_diag_dp_v3_11_3::basic_jsonnlohmann::json_abi_diag_dp_v3_11_3::ordered_map; typename std::enable_if<(nlohmann::json_abi_diag_dp_v3_11_3::detail::is_basic_json::value && (! std::is_same<nlohmann::json_abi_diag_dp_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>, BasicJsonType>::value)), int>::type = 0; ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::json_abi_diag_dp_v3_11_3::adl_serializer; BinaryType = std::vector; CustomBaseClass = void]’:
/home/hnampall/json/tests/src/unit-ordered_json.cpp:31:5: required from here
/home/hnampall/json/include/nlohmann/json.hpp:852:30: error: ‘std::size_t nlohmann::json_abi_diag_dp_v3_11_3::basic_jsonnlohmann::json_abi_diag_dp_v3_11_3::ordered_map::start_position’ is private within this context
852 | : start_position(val.start_position),
| ~~~~^~~~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:4255:17: note: declared private here
4255 | std::size_t start_position = std::string::npos;
| ^~~~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:853:28: error: ‘std::size_t nlohmann::json_abi_diag_dp_v3_11_3::basic_jsonnlohmann::json_abi_diag_dp_v3_11_3::ordered_map::end_position’ is private within this context
853 | end_position(val.end_position)
| ~~~~^~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:4257:17: note: declared private here
4257 | std::size_t end_position = std::string::npos;
| ^~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp: In instantiation of ‘nlohmann::json_abi_diag_dp_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>::basic_json(const BasicJsonType&) [with BasicJsonType = nlohmann::json_abi_diag_dp_v3_11_3::basic_json<>; typename std::enable_if<(nlohmann::json_abi_diag_dp_v3_11_3::detail::is_basic_json::value && (! std::is_same<nlohmann::json_abi_diag_dp_v3_11_3::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType, CustomBaseClass>, BasicJsonType>::value)), int>::type = 0; ObjectType = nlohmann::json_abi_diag_dp_v3_11_3::ordered_map; ArrayType = std::vector; StringType = std::__cxx11::basic_string; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::json_abi_diag_dp_v3_11_3::adl_serializer; BinaryType = std::vector; CustomBaseClass = void]’:
/home/hnampall/json/tests/src/unit-ordered_json.cpp:32:5: required from here
/home/hnampall/json/include/nlohmann/json.hpp:852:30: error: ‘std::size_t nlohmann::json_abi_diag_dp_v3_11_3::basic_json<>::start_position’ is private within this context
852 | : start_position(val.start_position),
| ~~~~^~~~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:4255:17: note: declared private here
4255 | std::size_t start_position = std::string::npos;
| ^~~~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:853:28: error: ‘std::size_t nlohmann::json_abi_diag_dp_v3_11_3::basic_json<>::end_position’ is private within this context
853 | end_position(val.end_position)
| ~~~~^~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:4257:17: note: declared private here
4257 | std::size_t end_position = std::string::npos;
| ^~~~~~~~~~~~
make[2]: *** [tests/CMakeFiles/test-ordered_json_cpp11.dir/build.make:76: tests/CMakeFiles/test-ordered_json_cpp11.dir/src/unit-ordered_json.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:2633: tests/CMakeFiles/test-ordered_json_cpp11.dir/all] Error 2
make: *** [Makefile:166: all] Error 2
Minimal code example
No response
Error messages
/home/hnampall/json/include/nlohmann/json.hpp:852:30: error: ‘std::size_t nlohmann::json_abi_diag_dp_v3_11_3::basic_json<>::start_position’ is private within this context
852 | : start_position(val.start_position),
| ~~~~^~~~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:4255:17: note: declared private here
4255 | std::size_t start_position = std::string::npos;
| ^~~~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:853:28: error: ‘std::size_t nlohmann::json_abi_diag_dp_v3_11_3::basic_json<>::end_position’ is private within this context
853 | end_position(val.end_position)
| ~~~~^~~~~~~~~~~~
/home/hnampall/json/include/nlohmann/json.hpp:4257:17: note: declared private here
4257 | std::size_t end_position = std::string::npos;
Compiler and operating system
gcc 9.4.0 (Ubuntu 9.4.0-1ubuntu1~20.04.2) on Ubuntu 20.0.1 - focal
Library version
develop branch
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.