Fix the red CI on develop (json_view pointer tokens, bson, from_json tests, Infer, IWYU) (#5942)

* json_view: pointer tokens that cannot be array indices create objects

editable_document::set() chose an array for a null parent whenever the
token consisted of digits, so "01" threw parse_error.106 and the empty
token threw, while basic_json::operator[](json_pointer) has created an
object for such tokens since #5358. This broke
unit-json_view_edit_values on develop. Use the same RFC 6901 array index
test as basic_json.

Also re-indent the unflatten test that the astyle check flagged.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix the other red jobs on develop

- unit-bson: initialize recorder::events in its declaration (-Weffc++)
- unit-json_view_from_json: suppress -Wexit-time-destructors for the
  serialize-enum tables and -Wfloat-equal for same()
- unit-pointer_access: @infer-ignore NULLPTR_DEREFERENCE for the
  dereferences after get_ptr() that Infer reports
- json_view.hpp: IWYU no_include for the detail headers that the view
  code uses through nlohmann/json.hpp

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

* Fix GCC warnings in the json_view from_json test

GCC (-Weffc++, -Wfloat-equal) rejected unit-json_view_from_json.cpp
(ci_test_standards_gcc (20)): initialize the members of shape and
with_names, and suppress -Wfloat-equal for GCC like for clang.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>

---------

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann authored and GitHub committed 2026-10-27 07:27:34 +01:00
1 parent 21ec9bd801
commit 2bb2feeef4
6 files changed
+42 -14

No files matched your search

+16 -5
View File
@@ -41,6 +41,13 @@ using nlohmann::ordered_json_document;
#include <optional>
#endif
// NLOHMANN_JSON_SERIALIZE_ENUM uses a static std::pair; same() compares floating-point values on purpose
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
DOCTEST_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors")
DOCTEST_CLANG_SUPPRESS_WARNING("-Wfloat-equal")
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
// The from_json() functions of the NLOHMANN_DEFINE_TYPE_* and
// NLOHMANN_JSON_SERIALIZE_ENUM macros read views directly; other from_json()
// functions get the value of materialize().
@@ -61,10 +68,11 @@ struct point
struct shape
{
std::string name;
std::vector<point> points;
point center;
std::map<std::string, point> named;
// initialized for GCC -Weffc++
std::string name{};
std::vector<point> points{};
point center{};
std::map<std::string, point> named{};
NLOHMANN_DEFINE_TYPE_INTRUSIVE(shape, name, points, center, named)
};
@@ -79,7 +87,7 @@ NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(with_defaults, a, b, c)
struct with_names
{
int value = 0;
std::string text;
std::string text{}; // initialized for GCC -Weffc++
};
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_NAMES(with_names, "Value", value, "Text", text)
@@ -447,3 +455,6 @@ TEST_CASE("json_view from_json")
}
#endif
}
DOCTEST_CLANG_SUPPRESS_WARNING_POP
DOCTEST_GCC_SUPPRESS_WARNING_POP