Skip to content
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ UTF-8 decoding is performed using a state machine based on Bjoern Hoehrmann's '[
- **[@ximion](https://github.com/ximion)** - Added support for installation with meson
- **[@rafal-c](https://github.com/rafal-c)** - Added a formatting flag
- **[@jfsimoneau](https://github.com/jfsimoneau)** - Fixed a meson option
- **[@ShereeMorphett](https://github.com/ShereeMorphett)** - Fixed reinterpret_cast usage
<br>

## Contact
Expand Down
4 changes: 2 additions & 2 deletions include/toml++/impl/array.inl
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ TOML_NAMESPACE_START
auto type = child.elems_[i]->type();
if (type == node_type::array)
{
array& arr = *reinterpret_cast<array*>(child.elems_[i].get());
array& arr = *static_cast<array*>(child.elems_[i].get());
if (!arr.empty())
flatten_child(std::move(arr), dest_index);
}
Expand Down Expand Up @@ -370,7 +370,7 @@ TOML_NAMESPACE_START

const bool equal = lhs.elems_[i]->visit(
[&](const auto& lhs_) noexcept
{ return lhs_ == *reinterpret_cast<std::remove_reference_t<decltype(lhs_)>*>(&rhs_); });
{ return lhs_ == *static_cast<std::remove_reference_t<decltype(lhs_)>*>(&rhs_); });
if (!equal)
return false;
}
Expand Down
14 changes: 7 additions & 7 deletions include/toml++/impl/formatter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -482,13 +482,13 @@ TOML_IMPL_NAMESPACE_START
TOML_ASSUME(type > node_type::array);
switch (type)
{
case node_type::string: print(*reinterpret_cast<const value<std::string>*>(&val_node)); break;
case node_type::integer: print(*reinterpret_cast<const value<int64_t>*>(&val_node)); break;
case node_type::floating_point: print(*reinterpret_cast<const value<double>*>(&val_node)); break;
case node_type::boolean: print(*reinterpret_cast<const value<bool>*>(&val_node)); break;
case node_type::date: print(*reinterpret_cast<const value<date>*>(&val_node)); break;
case node_type::time: print(*reinterpret_cast<const value<time>*>(&val_node)); break;
case node_type::date_time: print(*reinterpret_cast<const value<date_time>*>(&val_node)); break;
case node_type::string: print(*static_cast<const value<std::string>*>(&val_node)); break;
case node_type::integer: print(*static_cast<const value<int64_t>*>(&val_node)); break;
case node_type::floating_point: print(*static_cast<const value<double>*>(&val_node)); break;
case node_type::boolean: print(*static_cast<const value<bool>*>(&val_node)); break;
case node_type::date: print(*static_cast<const value<date>*>(&val_node)); break;
case node_type::time: print(*static_cast<const value<time>*>(&val_node)); break;
case node_type::date_time: print(*static_cast<const value<date_time>*>(&val_node)); break;
default: TOML_UNREACHABLE;
}
}
Expand Down
12 changes: 6 additions & 6 deletions include/toml++/impl/json_formatter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ TOML_NAMESPACE_START
TOML_ASSUME(type != node_type::none);
switch (type)
{
case node_type::table: print(*reinterpret_cast<const table*>(&v)); break;
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
case node_type::table: print(*static_cast<const table*>(&v)); break;
case node_type::array: print(*static_cast<const array*>(&v)); break;
default: print_value(v, type);
}
}
Expand Down Expand Up @@ -89,8 +89,8 @@ TOML_NAMESPACE_START
TOML_ASSUME(type != node_type::none);
switch (type)
{
case node_type::table: print(*reinterpret_cast<const table*>(&v)); break;
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
case node_type::table: print(*static_cast<const table*>(&v)); break;
case node_type::array: print(*static_cast<const array*>(&v)); break;
default: print_value(v, type);
}
}
Expand All @@ -109,8 +109,8 @@ TOML_NAMESPACE_START

switch (auto source_type = source().type())
{
case node_type::table: print(*reinterpret_cast<const table*>(&source())); break;
case node_type::array: print(*reinterpret_cast<const array*>(&source())); break;
case node_type::table: print(*static_cast<const table*>(&source())); break;
case node_type::array: print(*static_cast<const array*>(&source())); break;
default: print_value(source(), source_type);
}
}
Expand Down
8 changes: 4 additions & 4 deletions include/toml++/impl/node.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ TOML_NAMESPACE_START
{
using out_ref = ref_cast_type<T, node&>;
using out_type = std::remove_reference_t<out_ref>;
return static_cast<out_ref>(*reinterpret_cast<out_type*>(this));
return static_cast<out_ref>(*static_cast<out_type*>(this));
}

template <typename T>
Expand All @@ -119,7 +119,7 @@ TOML_NAMESPACE_START
{
using out_ref = ref_cast_type<T, node&&>;
using out_type = std::remove_reference_t<out_ref>;
return static_cast<out_ref>(*reinterpret_cast<out_type*>(this));
return static_cast<out_ref>(*static_cast<out_type*>(this));
}

template <typename T>
Expand All @@ -128,7 +128,7 @@ TOML_NAMESPACE_START
{
using out_ref = ref_cast_type<T, const node&>;
using out_type = std::remove_reference_t<out_ref>;
return static_cast<out_ref>(*reinterpret_cast<out_type*>(this));
return static_cast<out_ref>(*static_cast<out_type*>(this));
}

template <typename T>
Expand All @@ -137,7 +137,7 @@ TOML_NAMESPACE_START
{
using out_ref = ref_cast_type<T, const node&&>;
using out_type = std::remove_reference_t<out_ref>;
return static_cast<out_ref>(*reinterpret_cast<out_type*>(this));
return static_cast<out_ref>(*static_cast<out_type*>(this));
}

/// \endcond
Expand Down
1 change: 0 additions & 1 deletion include/toml++/impl/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,6 @@
__pragma(warning(disable : 4710)) /* function not inlined */ \
__pragma(warning(disable : 4711)) /* function selected for automatic expansion */ \
__pragma(warning(disable : 4820)) /* N bytes padding added */ \
__pragma(warning(disable : 4946)) /* reinterpret_cast used between related classes */ \
__pragma(warning(disable : 5026)) /* move constructor was implicitly defined as deleted */ \
__pragma(warning(disable : 5027)) /* move assignment operator was implicitly defined as deleted */ \
__pragma(warning(disable : 5039)) /* potentially throwing function passed to 'extern "C"' function */ \
Expand Down
2 changes: 1 addition & 1 deletion include/toml++/impl/table.inl
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ TOML_NAMESPACE_START

const bool equal = l->second->visit(
[&](const auto& lhs_) noexcept
{ return lhs_ == *reinterpret_cast<std::remove_reference_t<decltype(lhs_)>*>(&rhs_); });
{ return lhs_ == *static_cast<std::remove_reference_t<decltype(lhs_)>*>(&rhs_); });
if (!equal)
return false;
}
Expand Down
40 changes: 20 additions & 20 deletions include/toml++/impl/toml_formatter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ TOML_ANON_NAMESPACE_START
{
case node_type::table:
{
auto& tbl = *reinterpret_cast<const table*>(&node);
auto& tbl = *static_cast<const table*>(&node);
if (tbl.empty())
return 2u; // "{}"
size_t weight = 3u; // "{ }"
Expand All @@ -45,7 +45,7 @@ TOML_ANON_NAMESPACE_START

case node_type::array:
{
auto& arr = *reinterpret_cast<const array*>(&node);
auto& arr = *static_cast<const array*>(&node);
if (arr.empty())
return 2u; // "[]"
size_t weight = 3u; // "[ ]"
Expand All @@ -62,13 +62,13 @@ TOML_ANON_NAMESPACE_START
{
// todo: proper utf8 decoding?
// todo: tab awareness?
auto& str = (*reinterpret_cast<const value<std::string>*>(&node)).get();
auto& str = (*static_cast<const value<std::string>*>(&node)).get();
return str.length() + 2u; // + ""
}

case node_type::integer:
{
auto val = (*reinterpret_cast<const value<int64_t>*>(&node)).get();
auto val = (*static_cast<const value<int64_t>*>(&node)).get();
if (!val)
return 1u;
size_t weight = {};
Expand All @@ -82,7 +82,7 @@ TOML_ANON_NAMESPACE_START

case node_type::floating_point:
{
auto val = (*reinterpret_cast<const value<double>*>(&node)).get();
auto val = (*static_cast<const value<double>*>(&node)).get();
if (val == 0.0)
return 3u; // "0.0"
size_t weight = 2u; // ".0"
Expand Down Expand Up @@ -160,8 +160,8 @@ TOML_NAMESPACE_START
TOML_ASSUME(type != node_type::none);
switch (type)
{
case node_type::table: print_inline(*reinterpret_cast<const table*>(&v)); break;
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
case node_type::table: print_inline(*static_cast<const table*>(&v)); break;
case node_type::array: print(*static_cast<const array*>(&v)); break;
default: print_value(v, type);
}
}
Expand Down Expand Up @@ -217,8 +217,8 @@ TOML_NAMESPACE_START
TOML_ASSUME(type != node_type::none);
switch (type)
{
case node_type::table: print_inline(*reinterpret_cast<const table*>(&v)); break;
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
case node_type::table: print_inline(*static_cast<const table*>(&v)); break;
case node_type::array: print(*static_cast<const array*>(&v)); break;
default: print_value(v, type);
}
}
Expand All @@ -243,14 +243,14 @@ TOML_NAMESPACE_START
if (!arr || !arr->is_array_of_tables())
return false;

return !reinterpret_cast<const table*>(&(*arr)[0])->is_inline();
return !static_cast<const table*>(&(*arr)[0])->is_inline();
};

// values, arrays, and inline tables/table arrays
for (auto&& [k, v] : tbl)
{
const auto type = v.type();
if ((type == node_type::table && !reinterpret_cast<const table*>(&v)->is_inline())
if ((type == node_type::table && !static_cast<const table*>(&v)->is_inline())
|| (type == node_type::array && is_non_inline_array_of_tables(v)))
continue;

Expand All @@ -265,8 +265,8 @@ TOML_NAMESPACE_START
TOML_ASSUME(type != node_type::none);
switch (type)
{
case node_type::table: print_inline(*reinterpret_cast<const table*>(&v)); break;
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
case node_type::table: print_inline(*static_cast<const table*>(&v)); break;
case node_type::array: print(*static_cast<const array*>(&v)); break;
default: print_value(v, type);
}
}
Expand All @@ -286,9 +286,9 @@ TOML_NAMESPACE_START
for (auto&& [k, v] : tbl)
{
const auto type = v.type();
if (type != node_type::table || reinterpret_cast<const table*>(&v)->is_inline())
if (type != node_type::table || static_cast<const table*>(&v)->is_inline())
continue;
auto& child_tbl = *reinterpret_cast<const table*>(&v);
auto& child_tbl = *static_cast<const table*>(&v);

// we can skip indenting and emitting the headers for tables that only contain other tables
// (so we don't over-nest)
Expand All @@ -303,7 +303,7 @@ TOML_NAMESPACE_START
switch (child_type)
{
case node_type::table:
if (reinterpret_cast<const table*>(&child_v)->is_inline())
if (static_cast<const table*>(&child_v)->is_inline())
child_value_count++;
else
child_table_count++;
Expand Down Expand Up @@ -349,7 +349,7 @@ TOML_NAMESPACE_START
{
if (!is_non_inline_array_of_tables(v))
continue;
auto& arr = *reinterpret_cast<const array*>(&v);
auto& arr = *static_cast<const array*>(&v);

if (indent_sub_tables())
increase_indent();
Expand All @@ -363,7 +363,7 @@ TOML_NAMESPACE_START
print_key_path();
print_unformatted("]]"sv);
pending_table_separator_ = true;
print(*reinterpret_cast<const table*>(&arr[i]));
print(*static_cast<const table*>(&arr[i]));
}

key_path_.pop_back();
Expand All @@ -382,7 +382,7 @@ TOML_NAMESPACE_START
{
case node_type::table:
{
auto& tbl = *reinterpret_cast<const table*>(&source());
auto& tbl = *static_cast<const table*>(&source());
if (tbl.is_inline())
print_inline(tbl);
else
Expand All @@ -393,7 +393,7 @@ TOML_NAMESPACE_START
break;
}

case node_type::array: print(*reinterpret_cast<const array*>(&source())); break;
case node_type::array: print(*static_cast<const array*>(&source())); break;

default: print_value(source(), source_type);
}
Expand Down
18 changes: 9 additions & 9 deletions include/toml++/impl/yaml_formatter.inl
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ TOML_NAMESPACE_START
TOML_ASSUME(type != node_type::none);
switch (type)
{
case node_type::table: print(*reinterpret_cast<const table*>(&v)); break;
case node_type::array: print(*reinterpret_cast<const array*>(&v)); break;
case node_type::string: print_yaml_string(*reinterpret_cast<const value<std::string>*>(&v)); break;
case node_type::table: print(*static_cast<const table*>(&v)); break;
case node_type::array: print(*static_cast<const array*>(&v)); break;
case node_type::string: print_yaml_string(*static_cast<const value<std::string>*>(&v)); break;
default: print_value(v, type);
}
}
Expand Down Expand Up @@ -128,9 +128,9 @@ TOML_NAMESPACE_START
TOML_ASSUME(type != node_type::none);
switch (type)
{
case node_type::table: print(*reinterpret_cast<const table*>(&v), true); break;
case node_type::array: print(*reinterpret_cast<const array*>(&v), true); break;
case node_type::string: print_yaml_string(*reinterpret_cast<const value<std::string>*>(&v)); break;
case node_type::table: print(*static_cast<const table*>(&v), true); break;
case node_type::array: print(*static_cast<const array*>(&v), true); break;
case node_type::string: print_yaml_string(*static_cast<const value<std::string>*>(&v)); break;
default: print_value(v, type);
}
}
Expand All @@ -148,12 +148,12 @@ TOML_NAMESPACE_START
{
case node_type::table:
decrease_indent(); // so root kvps and tables have the same indent
print(*reinterpret_cast<const table*>(&source()));
print(*static_cast<const table*>(&source()));
break;

case node_type::array: print(*reinterpret_cast<const array*>(&source())); break;
case node_type::array: print(*static_cast<const array*>(&source())); break;

case node_type::string: print_yaml_string(*reinterpret_cast<const value<std::string>*>(&source())); break;
case node_type::string: print_yaml_string(*static_cast<const value<std::string>*>(&source())); break;

default: print_value(source(), source_type);
}
Expand Down
Loading
Loading