diff --git a/include/nlohmann/detail/view/builder.hpp b/include/nlohmann/detail/view/builder.hpp index 45f547072..2e0151b31 100644 --- a/include/nlohmann/detail/view/builder.hpp +++ b/include/nlohmann/detail/view/builder.hpp @@ -418,6 +418,14 @@ class builder return w; } + /// a compile-time option as a runtime condition: testing the template + /// argument directly makes a condition like `TrailingCommas && c == ']'` + /// constant when the option is off, which MSVC reports as C4127 + static NLOHMANN_VIEW_ALWAYS_INLINE bool enabled(bool option) noexcept + { + return option; + } + /// The parse state and the parser proper. The cursor is a local object of /// run() whose address never escapes (everything it calls out of line is a /// member of the builder and gets the positions it needs), so that the @@ -547,7 +555,7 @@ arr_next: { return false; } - if (TrailingCommas && cur() == ']') + if (enabled(TrailingCommas) && cur() == ']') { ++p; goto close_container; @@ -614,7 +622,7 @@ obj_next: { return false; } - if (TrailingCommas && cur() == '}') + if (enabled(TrailingCommas) && cur() == '}') { ++p; goto close_container; @@ -756,7 +764,7 @@ indent_done: { ++p; } - if (Comments && cur() == '/') + if (enabled(Comments) && cur() == '/') { const unsigned char* const q = cold.comment(p); if (q == nullptr) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 8c81b9123..71cfe2322 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -279,6 +279,10 @@ if(json_32bit_test_only) elseif(NOT json_32bit_test) list(FILTER files EXCLUDE REGEX src/unit-32bit.cpp) endif() +if(NOT JSON_MultipleHeaders) + # the internal headers of json_view are not part of a single header yet + list(FILTER files EXCLUDE REGEX src/unit-json_view_builder.cpp) +endif() foreach(file ${files}) json_test_add_test_for(${file} MAIN test_main CXX_STANDARDS ${test_cxx_standards} ${test_force})