From a563917a880fcdca98d5ae93803b3da5ac6cc3aa Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Sat, 11 Jun 2022 08:51:07 +0200 Subject: [PATCH 1/5] Enable JSON_MultipleHeaders by default --- CMakeLists.txt | 2 +- cmake/ci.cmake | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 632e6dec27..aae5fb6e36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,7 +43,7 @@ option(JSON_Diagnostics "Use extended diagnostic messages." O option(JSON_ImplicitConversions "Enable implicit conversions." ON) option(JSON_LegacyDiscardedValueComparison "Enable legacy discarded value comparison." OFF) option(JSON_Install "Install CMake targets during install step." ${MAIN_PROJECT}) -option(JSON_MultipleHeaders "Use non-amalgamated version of the library." OFF) +option(JSON_MultipleHeaders "Use non-amalgamated version of the library." ON) option(JSON_SystemInclude "Include as system headers (skip for clang-tidy)." OFF) if (JSON_CI) diff --git a/cmake/ci.cmake b/cmake/ci.cmake index d813a17739..fb705a687d 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -416,7 +416,7 @@ set(GCC_CXXFLAGS add_custom_target(ci_test_gcc COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON + -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_gcc COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_gcc COMMAND cd ${PROJECT_BINARY_DIR}/build_gcc && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure @@ -426,7 +426,7 @@ add_custom_target(ci_test_gcc add_custom_target(ci_test_clang COMMAND CXX=${CLANG_TOOL} CXXFLAGS="${CLANG_CXXFLAGS}" ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON + -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang COMMAND cd ${PROJECT_BINARY_DIR}/build_clang && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure @@ -468,7 +468,7 @@ endforeach() add_custom_target(ci_test_noexceptions COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw + -DJSON_BuildTests=ON -DCMAKE_CXX_FLAGS=-DJSON_NOEXCEPTION -DDOCTEST_TEST_FILTER=--no-throw -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noexceptions COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_noexceptions COMMAND cd ${PROJECT_BINARY_DIR}/build_noexceptions && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure @@ -482,7 +482,7 @@ add_custom_target(ci_test_noexceptions add_custom_target(ci_test_noimplicitconversions COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON -DJSON_ImplicitConversions=OFF + -DJSON_BuildTests=ON -DJSON_ImplicitConversions=OFF -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_noimplicitconversions COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_noimplicitconversions COMMAND cd ${PROJECT_BINARY_DIR}/build_noimplicitconversions && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure @@ -496,7 +496,7 @@ add_custom_target(ci_test_noimplicitconversions add_custom_target(ci_test_diagnostics COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON -DJSON_Diagnostics=ON + -DJSON_BuildTests=ON -DJSON_Diagnostics=ON -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_diagnostics COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_diagnostics COMMAND cd ${PROJECT_BINARY_DIR}/build_diagnostics && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure @@ -510,7 +510,7 @@ add_custom_target(ci_test_diagnostics add_custom_target(ci_test_legacycomparison COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja - -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON -DJSON_LegacyDiscardedValueComparison=ON + -DJSON_BuildTests=ON -DJSON_LegacyDiscardedValueComparison=ON -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_legacycomparison COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_legacycomparison COMMAND cd ${PROJECT_BINARY_DIR}/build_legacycomparison && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure @@ -524,7 +524,7 @@ add_custom_target(ci_test_legacycomparison add_custom_target(ci_test_coverage COMMAND CXX=g++ ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CXX_FLAGS="--coverage;-fprofile-arcs;-ftest-coverage" - -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON + -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_coverage COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure @@ -664,7 +664,7 @@ add_custom_target(ci_clang_tidy COMMAND CXX=${CLANG_TOOL} ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_CXX_CLANG_TIDY=${CLANG_TIDY_TOOL} - -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON + -DJSON_BuildTests=ON -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_clang_tidy COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_clang_tidy COMMENT "Check code with Clang-Tidy" @@ -691,7 +691,7 @@ add_custom_target(ci_pvs_studio add_custom_target(ci_infer COMMAND mkdir -p ${PROJECT_BINARY_DIR}/build_infer - COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON -DJSON_MultipleHeaders=ON + COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} compile -- ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Debug ${PROJECT_SOURCE_DIR} -DJSON_BuildTests=ON COMMAND cd ${PROJECT_BINARY_DIR}/build_infer && ${INFER_TOOL} run -- make COMMENT "Check code with Infer" ) From eef7437738b802f3713d8551115ede65179a56a0 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Sat, 11 Jun 2022 09:28:37 +0200 Subject: [PATCH 2/5] CI: add single-header build to ci_test_amalgamation --- cmake/ci.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/ci.cmake b/cmake/ci.cmake index fb705a687d..db9aae62ec 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -577,6 +577,13 @@ add_custom_target(ci_test_amalgamation COMMAND ${ASTYLE_TOOL} ${ASTYLE_FLAGS} ${INDENT_FILES} COMMAND cd ${PROJECT_SOURCE_DIR} && for FILE in `find . -name '*.orig'`\; do false \; done + COMMAND CXX=${GCC_TOOL} CXXFLAGS="${GCC_CXXFLAGS}" ${CMAKE_COMMAND} + -DCMAKE_BUILD_TYPE=Debug -GNinja + -DJSON_BuildTests=ON -DJSON_MultipleHeader=OFF -DJSON_FastTests=ON + -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_single_header + COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_single_header + COMMAND cd ${PROJECT_BINARY_DIR}/build_single_header && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} COMMENT "Check amalgamation and indentation" ) From 4be1e2bd0ecf563624651976e3b1f970236df6bf Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Sat, 11 Jun 2022 14:55:18 +0200 Subject: [PATCH 3/5] CI: Enable 32bit unit test --- cmake/ci.cmake | 7 +++ tests/CMakeLists.txt | 104 +++++++++++++++++++++---------------------- 2 files changed, 59 insertions(+), 52 deletions(-) diff --git a/cmake/ci.cmake b/cmake/ci.cmake index db9aae62ec..26b11a8486 100644 --- a/cmake/ci.cmake +++ b/cmake/ci.cmake @@ -529,6 +529,13 @@ add_custom_target(ci_test_coverage COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + COMMAND CXX=g++ ${CMAKE_COMMAND} + -DCMAKE_BUILD_TYPE=Debug -GNinja -DCMAKE_CXX_FLAGS="-m32;--coverage;-fprofile-arcs;-ftest-coverage" + -DJSON_BuildTests=ON -DJSON_32bitTest=ONLY + -S${PROJECT_SOURCE_DIR} -B${PROJECT_BINARY_DIR}/build_coverage32 + COMMAND ${CMAKE_COMMAND} --build ${PROJECT_BINARY_DIR}/build_coverage32 + COMMAND cd ${PROJECT_BINARY_DIR}/build_coverage32 && ${CMAKE_CTEST_COMMAND} --parallel ${N} --output-on-failure + COMMAND ${LCOV_TOOL} --directory . --capture --output-file json.info --rc lcov_branch_coverage=1 COMMAND ${LCOV_TOOL} -e json.info ${SRC_FILES} --output-file json.info.filtered --rc lcov_branch_coverage=1 COMMAND ${CMAKE_SOURCE_DIR}/tests/thirdparty/imapdl/filterbr.py json.info.filtered > json.info.filtered.noexcept diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index ef87c49092..a0193c32c2 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -2,8 +2,8 @@ cmake_minimum_required(VERSION 3.13) option(JSON_Valgrind "Execute test suite with Valgrind." OFF) option(JSON_FastTests "Skip expensive/slow tests." OFF) -option(JSON_32bitTest "Enable the 32bit unit test." OFF) +set(JSON_32bitTest AUTO CACHE STRING "Enable the 32bit unit test (ON/OFF/AUTO/ONLY).") set(JSON_TestStandards "" CACHE STRING "The list of standards to test explicitly.") include(test) @@ -34,40 +34,32 @@ endif() # test_main library with shared code to speed up build and common settings ############################################################################# -set(test_main_SOURCES src/unit.cpp) -set(test_main_COMPILE_DEFINITIONS PUBLIC +add_library(test_main OBJECT src/unit.cpp) +target_compile_definitions(test_main PUBLIC DOCTEST_CONFIG_SUPER_FAST_ASSERTS JSON_TEST_KEEP_MACROS) -set(test_main_COMPILE_FEATURES PRIVATE cxx_std_11) -set(test_main_COMPILE_OPTIONS - PUBLIC - $<$:/EHsc;$<$:/Od>> - # MSVC: Force to always compile with W4 - # Disable warning C4566: character represented by universal-character-name '\uFF01' - # cannot be represented in the current code page (1252) - # Disable warning C4996: 'nlohmann::basic_json<...>::operator <<': was declared deprecated - $<$:/W4 /wd4566 /wd4996> - # https://github.com/nlohmann/json/issues/1114 - $<$:/bigobj> $<$:-Wa,-mbig-obj> - - # https://github.com/nlohmann/json/pull/3229 - $<$:-diag-disable=2196> - - $<$>:-Wno-deprecated;-Wno-float-equal> - $<$:-Wno-deprecated-declarations> - $<$:-diag-disable=1786>) -set(test_main_INCLUDE_DIRECTORIES PUBLIC +target_compile_features(test_main PRIVATE cxx_std_11) +target_compile_options(test_main PUBLIC + $<$:/EHsc;$<$:/Od>> + # MSVC: Force to always compile with W4 + # Disable warning C4566: character represented by universal-character-name '\uFF01' + # cannot be represented in the current code page (1252) + # Disable warning C4996: 'nlohmann::basic_json<...>::operator <<': was declared deprecated + $<$:/W4 /wd4566 /wd4996> + # https://github.com/nlohmann/json/issues/1114 + $<$:/bigobj> $<$:-Wa,-mbig-obj> + + # https://github.com/nlohmann/json/pull/3229 + $<$:-diag-disable=2196> + + $<$>:-Wno-deprecated;-Wno-float-equal> + $<$:-Wno-deprecated-declarations> + $<$:-diag-disable=1786>) +target_include_directories(test_main PUBLIC thirdparty/doctest thirdparty/fifo_map ${PROJECT_BINARY_DIR}/include) -set(test_main_LINK_LIBRARIES PUBLIC ${NLOHMANN_JSON_TARGET_NAME}) - -add_library(test_main OBJECT ${test_main_SOURCES}) -target_compile_definitions(test_main ${test_main_COMPILE_DEFINITIONS}) -target_compile_features(test_main ${test_main_COMPILE_FEATURES}) -target_compile_options(test_main ${test_main_COMPILE_OPTIONS}) -target_include_directories(test_main ${test_main_INCLUDE_DIRECTORIES}) -target_link_libraries(test_main ${test_main_LINK_LIBRARIES}) +target_link_libraries(test_main PUBLIC ${NLOHMANN_JSON_TARGET_NAME}) ############################################################################# # define test- and standard-specific build settings @@ -124,34 +116,42 @@ message(STATUS "${msg}") # *DO* use json_test_set_test_options() above this line -file(GLOB files src/unit-*.cpp) -list(FILTER files EXCLUDE REGEX "src/unit-32bit.cpp") +string(TOUPPER "${JSON_32bitTest}" json_32bit_test) +if("${json_32bit_test}" STREQUAL AUTO) + # check if compiler is targeting 32bit by default + include(CheckTypeSize) + check_type_size("size_t" sizeof_size_t LANGUAGE CXX) + if(sizeof_size_t AND ${sizeof_size_t} EQUAL 4) + message(STATUS "Auto-enabling 32bit unit test.") + set(json_32bit_test ON) + else() + set(json_32bit_test OFF) + endif() +endif() + +if("${json_32bit_test}" STREQUAL ONLY) + set(files src/unit-32bit.cpp) +else() + file(GLOB files src/unit-*.cpp) + if("${json_32bit_test}" STREQUAL OFF) + list(FILTER files EXCLUDE REGEX src/unit-32bit.cpp) + endif() +endif() foreach(file ${files}) json_test_add_test_for(${file} MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force}) endforeach() -if(JSON_32bitTest) - add_library(test_main32 OBJECT ${test_main_SOURCES}) - target_compile_definitions(test_main32 ${test_main_COMPILE_DEFINITIONS}) - target_compile_features(test_main32 ${test_main_COMPILE_FEATURES}) - target_compile_options(test_main32 ${test_main_COMPILE_OPTIONS} -m32) - target_include_directories(test_main32 ${test_main_INCLUDE_DIRECTORIES}) - target_link_libraries(test_main32 ${test_main_LINK_LIBRARIES}) - target_link_options(test_main32 PUBLIC -m32) - - json_test_add_test_for("src/unit-32bit.cpp" MAIN test_main32 - CXX_STANDARDS ${test_cxx_standards} ${test_force}) +if(NOT "${json_32bit_test}" STREQUAL ONLY) + # test legacy comparison of discarded values + json_test_set_test_options(test-comparison_legacy + COMPILE_DEFINITIONS JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1 + ) + json_test_add_test_for(src/unit-comparison.cpp + NAME test-comparison_legacy + MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force} + ) endif() -# test legacy comparison of discarded values -json_test_set_test_options(test-comparison_legacy - COMPILE_DEFINITIONS JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON=1 -) -json_test_add_test_for(src/unit-comparison.cpp - NAME test-comparison_legacy - MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force} -) - # *DO NOT* use json_test_set_test_options() below this line ############################################################################# From 0216d727e9424be65370ed97f66f9f2fd42a61b5 Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Sat, 11 Jun 2022 09:21:38 +0200 Subject: [PATCH 4/5] Fix "-Wuseless-cast" warnings --- .../nlohmann/detail/input/binary_reader.hpp | 23 ++++++++++--------- single_include/nlohmann/json.hpp | 23 ++++++++++--------- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 9332af3e64..2052fbffdb 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -618,7 +618,8 @@ class binary_reader case 0x95: case 0x96: case 0x97: - return get_cbor_array(static_cast(static_cast(current) & 0x1Fu), tag_handler); + return get_cbor_array( + conditional_static_cast(static_cast(current) & 0x1Fu), tag_handler); case 0x98: // array (one-byte uint8_t for n follows) { @@ -635,13 +636,13 @@ class binary_reader case 0x9A: // array (four-byte uint32_t for n follow) { std::uint32_t len{}; - return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast(len), tag_handler); + return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast(len), tag_handler); } case 0x9B: // array (eight-byte uint64_t for n follow) { std::uint64_t len{}; - return get_number(input_format_t::cbor, len) && get_cbor_array(detail::conditional_static_cast(len), tag_handler); + return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast(len), tag_handler); } case 0x9F: // array (indefinite length) @@ -672,7 +673,7 @@ class binary_reader case 0xB5: case 0xB6: case 0xB7: - return get_cbor_object(static_cast(static_cast(current) & 0x1Fu), tag_handler); + return get_cbor_object(conditional_static_cast(static_cast(current) & 0x1Fu), tag_handler); case 0xB8: // map (one-byte uint8_t for n follows) { @@ -689,13 +690,13 @@ class binary_reader case 0xBA: // map (four-byte uint32_t for n follow) { std::uint32_t len{}; - return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast(len), tag_handler); + return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast(len), tag_handler); } case 0xBB: // map (eight-byte uint64_t for n follow) { std::uint64_t len{}; - return get_number(input_format_t::cbor, len) && get_cbor_object(detail::conditional_static_cast(len), tag_handler); + return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast(len), tag_handler); } case 0xBF: // map (indefinite length) @@ -1342,7 +1343,7 @@ class binary_reader case 0x8D: case 0x8E: case 0x8F: - return get_msgpack_object(static_cast(static_cast(current) & 0x0Fu)); + return get_msgpack_object(conditional_static_cast(static_cast(current) & 0x0Fu)); // fixarray case 0x90: @@ -1361,7 +1362,7 @@ class binary_reader case 0x9D: case 0x9E: case 0x9F: - return get_msgpack_array(static_cast(static_cast(current) & 0x0Fu)); + return get_msgpack_array(conditional_static_cast(static_cast(current) & 0x0Fu)); // fixstr case 0xA0: @@ -1498,7 +1499,7 @@ class binary_reader case 0xDD: // array 32 { std::uint32_t len{}; - return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast(len)); + return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast(len)); } case 0xDE: // map 16 @@ -1510,7 +1511,7 @@ class binary_reader case 0xDF: // map 32 { std::uint32_t len{}; - return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast(len)); + return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast(len)); } // negative fixint @@ -2115,7 +2116,7 @@ class binary_reader { return false; } - result = static_cast(number); + result = conditional_static_cast(number); return true; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index c5fd3fd0bf..54e93eb0d3 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -9303,7 +9303,8 @@ class binary_reader case 0x95: case 0x96: case 0x97: - return get_cbor_array(static_cast(static_cast(current) & 0x1Fu), tag_handler); + return get_cbor_array( + conditional_static_cast(static_cast(current) & 0x1Fu), tag_handler); case 0x98: // array (one-byte uint8_t for n follows) { @@ -9320,13 +9321,13 @@ class binary_reader case 0x9A: // array (four-byte uint32_t for n follow) { std::uint32_t len{}; - return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast(len), tag_handler); + return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast(len), tag_handler); } case 0x9B: // array (eight-byte uint64_t for n follow) { std::uint64_t len{}; - return get_number(input_format_t::cbor, len) && get_cbor_array(detail::conditional_static_cast(len), tag_handler); + return get_number(input_format_t::cbor, len) && get_cbor_array(conditional_static_cast(len), tag_handler); } case 0x9F: // array (indefinite length) @@ -9357,7 +9358,7 @@ class binary_reader case 0xB5: case 0xB6: case 0xB7: - return get_cbor_object(static_cast(static_cast(current) & 0x1Fu), tag_handler); + return get_cbor_object(conditional_static_cast(static_cast(current) & 0x1Fu), tag_handler); case 0xB8: // map (one-byte uint8_t for n follows) { @@ -9374,13 +9375,13 @@ class binary_reader case 0xBA: // map (four-byte uint32_t for n follow) { std::uint32_t len{}; - return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast(len), tag_handler); + return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast(len), tag_handler); } case 0xBB: // map (eight-byte uint64_t for n follow) { std::uint64_t len{}; - return get_number(input_format_t::cbor, len) && get_cbor_object(detail::conditional_static_cast(len), tag_handler); + return get_number(input_format_t::cbor, len) && get_cbor_object(conditional_static_cast(len), tag_handler); } case 0xBF: // map (indefinite length) @@ -10027,7 +10028,7 @@ class binary_reader case 0x8D: case 0x8E: case 0x8F: - return get_msgpack_object(static_cast(static_cast(current) & 0x0Fu)); + return get_msgpack_object(conditional_static_cast(static_cast(current) & 0x0Fu)); // fixarray case 0x90: @@ -10046,7 +10047,7 @@ class binary_reader case 0x9D: case 0x9E: case 0x9F: - return get_msgpack_array(static_cast(static_cast(current) & 0x0Fu)); + return get_msgpack_array(conditional_static_cast(static_cast(current) & 0x0Fu)); // fixstr case 0xA0: @@ -10183,7 +10184,7 @@ class binary_reader case 0xDD: // array 32 { std::uint32_t len{}; - return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast(len)); + return get_number(input_format_t::msgpack, len) && get_msgpack_array(conditional_static_cast(len)); } case 0xDE: // map 16 @@ -10195,7 +10196,7 @@ class binary_reader case 0xDF: // map 32 { std::uint32_t len{}; - return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast(len)); + return get_number(input_format_t::msgpack, len) && get_msgpack_object(conditional_static_cast(len)); } // negative fixint @@ -10800,7 +10801,7 @@ class binary_reader { return false; } - result = static_cast(number); + result = conditional_static_cast(number); return true; } From d4724abd2daf9f5f7b736f34b312dde5b406ed3a Mon Sep 17 00:00:00 2001 From: Florian Albrechtskirchinger Date: Sat, 11 Jun 2022 11:13:36 +0200 Subject: [PATCH 5/5] Remove coverage exclusion --- include/nlohmann/detail/input/binary_reader.hpp | 10 ++++------ single_include/nlohmann/json.hpp | 10 ++++------ 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/nlohmann/detail/input/binary_reader.hpp b/include/nlohmann/detail/input/binary_reader.hpp index 2052fbffdb..f5871ddf6e 100644 --- a/include/nlohmann/detail/input/binary_reader.hpp +++ b/include/nlohmann/detail/input/binary_reader.hpp @@ -2082,9 +2082,8 @@ class binary_reader } if (!value_in_range_of(number)) { - // undo coverage exclusion once the 32bit test is run as part of CI (#3524) - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, // LCOV_EXCL_LINE - exception_message(input_format, "integer value overflow", "size"), nullptr)); // LCOV_EXCL_LINE + return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, + exception_message(input_format, "integer value overflow", "size"), nullptr)); } result = static_cast(number); return true; @@ -2133,9 +2132,8 @@ class binary_reader } if (!value_in_range_of(number)) { - // undo coverage exclusion once the 32bit test is run as part of CI (#3524) - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, // LCOV_EXCL_LINE - exception_message(input_format, "integer value overflow", "size"), nullptr)); // LCOV_EXCL_LINE + return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, + exception_message(input_format, "integer value overflow", "size"), nullptr)); } result = detail::conditional_static_cast(number); return true; diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index 54e93eb0d3..830a0ed905 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -10767,9 +10767,8 @@ class binary_reader } if (!value_in_range_of(number)) { - // undo coverage exclusion once the 32bit test is run as part of CI (#3524) - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, // LCOV_EXCL_LINE - exception_message(input_format, "integer value overflow", "size"), nullptr)); // LCOV_EXCL_LINE + return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, + exception_message(input_format, "integer value overflow", "size"), nullptr)); } result = static_cast(number); return true; @@ -10818,9 +10817,8 @@ class binary_reader } if (!value_in_range_of(number)) { - // undo coverage exclusion once the 32bit test is run as part of CI (#3524) - return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, // LCOV_EXCL_LINE - exception_message(input_format, "integer value overflow", "size"), nullptr)); // LCOV_EXCL_LINE + return sax->parse_error(chars_read, get_token_string(), out_of_range::create(408, + exception_message(input_format, "integer value overflow", "size"), nullptr)); } result = detail::conditional_static_cast(number); return true;