mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 20:20:32 +00:00
Fix CI: MSVC C4127 in the view builder and the single-header test build
- msvc (Win32, /W4 /WX) reported C4127 (conditional expression is constant) for `TrailingCommas && cur() == ']'` and the like when the option is off. Route the template arguments through a static enabled() function, as json.hpp's nesting_depth_exhausted() does. - ci_test_single_header compiled unit-json_view_builder.cpp against single_include/, which does not contain the internal nlohmann/detail/view headers. Build that test only with the multiple headers. Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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})
|
||||
|
||||
Reference in New Issue
Block a user