fixed spurious Wnull-dereference warning on GCC

closes #164
This commit is contained in:
Mark Gillard 2022-08-08 22:59:09 +03:00
parent b6fa7e1891
commit 67c18a3251
4 changed files with 15 additions and 6 deletions

View File

@ -17,6 +17,7 @@ template:
#### Fixes:
- fixed `[dotted.table]` source columns sometimes being off by one (#152) (@vaartis)
- fixed spurious `Wnull-dereference` warning on GCC (#164) (@zaporozhets)
- fixed `print_to_stream` ambiguity for `size_t` (#167) (@acronce)
#### Additions:

View File

@ -576,6 +576,7 @@
TOML_PRAGMA_GCC(diagnostic ignored "-Wmissing-field-initializers") \
TOML_PRAGMA_GCC(diagnostic ignored "-Wmaybe-uninitialized") \
TOML_PRAGMA_GCC(diagnostic ignored "-Wnoexcept") \
TOML_PRAGMA_GCC(diagnostic ignored "-Wnull-dereference") \
static_assert(true)
#define TOML_POP_WARNINGS \

View File

@ -234,10 +234,13 @@ TOML_NAMESPACE_START
TOML_EXTERNAL_LINKAGE
void toml_formatter::print(const table& tbl)
{
static constexpr auto is_non_inline_array_of_tables = [](auto&& nde) noexcept
static constexpr auto is_non_inline_array_of_tables = [](const node& n) noexcept
{
auto arr = nde.as_array();
return arr && arr->is_array_of_tables() && !arr->template get_as<table>(0u)->is_inline();
const auto arr = n.as_array();
if (!arr || !arr->is_array_of_tables())
return false;
return !reinterpret_cast<const table*>(&(*arr)[0])->is_inline();
};
// values, arrays, and inline tables/table arrays

View File

@ -606,6 +606,7 @@
TOML_PRAGMA_GCC(diagnostic ignored "-Wmissing-field-initializers") \
TOML_PRAGMA_GCC(diagnostic ignored "-Wmaybe-uninitialized") \
TOML_PRAGMA_GCC(diagnostic ignored "-Wnoexcept") \
TOML_PRAGMA_GCC(diagnostic ignored "-Wnull-dereference") \
static_assert(true)
#define TOML_POP_WARNINGS \
@ -16578,10 +16579,13 @@ TOML_NAMESPACE_START
TOML_EXTERNAL_LINKAGE
void toml_formatter::print(const table& tbl)
{
static constexpr auto is_non_inline_array_of_tables = [](auto&& nde) noexcept
static constexpr auto is_non_inline_array_of_tables = [](const node& n) noexcept
{
auto arr = nde.as_array();
return arr && arr->is_array_of_tables() && !arr->template get_as<table>(0u)->is_inline();
const auto arr = n.as_array();
if (!arr || !arr->is_array_of_tables())
return false;
return !reinterpret_cast<const table*>(&(*arr)[0])->is_inline();
};
// values, arrays, and inline tables/table arrays