Fix ci issues
* Add checks for uninitialized m_value (this can happen due to exceptions in the ctor) * Add missing noexcept * Fix clang tidy errors
This commit is contained in:
parent
5a1a57510a
commit
96f75d27c4
@ -555,6 +555,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
|
||||
void destroy(value_t t)
|
||||
{
|
||||
if (object == nullptr)
|
||||
{
|
||||
//not initialized (e.g. due to exception in the ctor)
|
||||
return;
|
||||
}
|
||||
if (t == value_t::array || t == value_t::object)
|
||||
{
|
||||
// flatten the current json_value to a heap-allocated stack
|
||||
@ -4173,6 +4178,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
|
||||
void assert_invariant(const basic_json* parent = nullptr) const noexcept
|
||||
{
|
||||
if (m_value.object == nullptr)
|
||||
{
|
||||
//the data was not fully initialized (e.g. due to an exception in the ctor)
|
||||
return;
|
||||
}
|
||||
JSON_ASSERT(m_type != value_t::object || m_value.object != nullptr);
|
||||
JSON_ASSERT(m_type != value_t::array || m_value.array != nullptr);
|
||||
JSON_ASSERT(m_type != value_t::string || m_value.string != nullptr);
|
||||
@ -4197,11 +4207,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
{
|
||||
}
|
||||
|
||||
data() = default;
|
||||
data(data&&) = default;
|
||||
data(const data&) = default;
|
||||
data& operator=(data&&) = default;
|
||||
data& operator=(const data&) = default;
|
||||
data() noexcept = default;
|
||||
data(data&&) noexcept = default;
|
||||
data(const data&) noexcept = default;
|
||||
data& operator=(data&&) noexcept = default;
|
||||
data& operator=(const data&) noexcept = default;
|
||||
|
||||
~data() noexcept
|
||||
{
|
||||
|
||||
@ -19771,6 +19771,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
|
||||
void destroy(value_t t)
|
||||
{
|
||||
if (object == nullptr)
|
||||
{
|
||||
//not initialized (e.g. due to exception in the ctor)
|
||||
return;
|
||||
}
|
||||
if (t == value_t::array || t == value_t::object)
|
||||
{
|
||||
// flatten the current json_value to a heap-allocated stack
|
||||
@ -23389,6 +23394,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
|
||||
void assert_invariant(const basic_json* parent = nullptr) const noexcept
|
||||
{
|
||||
if (m_value.object == nullptr)
|
||||
{
|
||||
//the data was not fully initialized (e.g. due to an exception in the ctor)
|
||||
return;
|
||||
}
|
||||
JSON_ASSERT(m_type != value_t::object || m_value.object != nullptr);
|
||||
JSON_ASSERT(m_type != value_t::array || m_value.array != nullptr);
|
||||
JSON_ASSERT(m_type != value_t::string || m_value.string != nullptr);
|
||||
@ -23413,11 +23423,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
|
||||
{
|
||||
}
|
||||
|
||||
data() = default;
|
||||
data(data&&) = default;
|
||||
data(const data&) = default;
|
||||
data& operator=(data&&) = default;
|
||||
data& operator=(const data&) = default;
|
||||
data() noexcept = default;
|
||||
data(data&&) noexcept = default;
|
||||
data(const data&) noexcept = default;
|
||||
data& operator=(data&&) noexcept = default;
|
||||
data& operator=(const data&) noexcept = default;
|
||||
|
||||
~data() noexcept
|
||||
{
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <exception>
|
||||
#include <iostream>
|
||||
|
||||
struct Foo
|
||||
{
|
||||
@ -41,13 +42,14 @@ struct adl_serializer<Foo>
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
} // namespace nlohmann
|
||||
|
||||
TEST_CASE("check_for_mem_leak_on_adl_to_json-1")
|
||||
{
|
||||
try
|
||||
{
|
||||
nlohmann::json j = Foo {1, 0};
|
||||
const nlohmann::json j = Foo {1, 0};
|
||||
std::cout << j.dump() << "\n";
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@ -59,7 +61,8 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
|
||||
{
|
||||
try
|
||||
{
|
||||
nlohmann::json j = Foo {1, 1};
|
||||
const nlohmann::json j = Foo {1, 1};
|
||||
std::cout << j.dump() << "\n";
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@ -71,7 +74,8 @@ TEST_CASE("check_for_mem_leak_on_adl_to_json-2")
|
||||
{
|
||||
try
|
||||
{
|
||||
nlohmann::json j = Foo {1, 2};
|
||||
const nlohmann::json j = Foo {1, 2};
|
||||
std::cout << j.dump() << "\n";
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user