Skip to content

Commit

Permalink
Avoid -Wmaybe-uninitialized warnings in gcc (issue boostorg#27).
Browse files Browse the repository at this point in the history
  • Loading branch information
Romain-Geissler-1A committed Mar 27, 2020
1 parent 8ec9323 commit b0fa60c
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions include/boost/function/function_template.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,19 @@ namespace boost {
{
if (!f.empty()) {
this->vtable = f.vtable;
if (this->has_trivial_copy_and_destroy())
if (this->has_trivial_copy_and_destroy()) {
// Don't operate on storage directly since union type doesn't relax
// strict aliasing rules, despite of having member char type.
# if defined(BOOST_GCC) && (BOOST_GCC >= 40700)
# pragma GCC diagnostic push
// Ignore a gcc false positive https://github.com/boostorg/function/issues/27
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
# endif
std::memcpy(this->functor.data, f.functor.data, sizeof(boost::detail::function::function_buffer));
else
# if defined(BOOST_GCC) && (BOOST_GCC >= 40700)
# pragma GCC diagnostic pop
# endif
} else
get_vtable()->base.manager(f.functor, this->functor,
boost::detail::function::clone_functor_tag);
}
Expand Down Expand Up @@ -987,11 +995,19 @@ namespace boost {
BOOST_TRY {
if (!f.empty()) {
this->vtable = f.vtable;
if (this->has_trivial_copy_and_destroy())
if (this->has_trivial_copy_and_destroy()) {
// Don't operate on storage directly since union type doesn't relax
// strict aliasing rules, despite of having member char type.
# if defined(BOOST_GCC) && (BOOST_GCC >= 40700)
# pragma GCC diagnostic push
// Ignore a gcc false positive https://github.com/boostorg/function/issues/27
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
# endif
std::memcpy(this->functor.data, f.functor.data, sizeof(this->functor.data));
else
# if defined(BOOST_GCC) && (BOOST_GCC >= 40700)
# pragma GCC diagnostic pop
# endif
} else
get_vtable()->base.manager(f.functor, this->functor,
boost::detail::function::move_functor_tag);
f.vtable = 0;
Expand Down

0 comments on commit b0fa60c

Please sign in to comment.