mirror of
https://github.com/nlohmann/json.git
synced 2026-10-01 04:00:31 +00:00
Stop the noexcept null constructor delegating to a throwing one
basic_json(std::nullptr_t) delegated to basic_json(value_t), whose underlying json_value(value_t) constructor allocates for other types and can therefore throw, which is why the noexcept had a NOLINT(bugprone-exception-escape). The delegated-to constructor also called assert_invariant() a second time. The default member initializers of data already produce the same null state (a value-initialized, i.e. zeroed, union with object == nullptr), so the delegation and its NOLINT can simply be dropped. Part of #5724 Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
@@ -1578,8 +1578,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
|
||||
/// @brief create a null object
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
|
||||
basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape)
|
||||
: basic_json(value_t::null)
|
||||
basic_json(std::nullptr_t = nullptr) noexcept
|
||||
{
|
||||
assert_invariant();
|
||||
}
|
||||
|
||||
@@ -27659,8 +27659,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
|
||||
/// @brief create a null object
|
||||
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
|
||||
basic_json(std::nullptr_t = nullptr) noexcept // NOLINT(bugprone-exception-escape)
|
||||
: basic_json(value_t::null)
|
||||
basic_json(std::nullptr_t = nullptr) noexcept
|
||||
{
|
||||
assert_invariant();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user