From 7c90434317894f1a0c63c7a395ddf569eff1d308 Mon Sep 17 00:00:00 2001 From: Romain Geissler Date: Fri, 27 Mar 2020 18:56:14 +0000 Subject: [PATCH] Avoid -Wmaybe-uninitialized warnings in gcc (issue #27). --- include/boost/function/function_template.hpp | 26 +++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/include/boost/function/function_template.hpp b/include/boost/function/function_template.hpp index 56f6bb4..26f1d67 100644 --- a/include/boost/function/function_template.hpp +++ b/include/boost/function/function_template.hpp @@ -898,11 +898,20 @@ 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 + // This warning is technically correct, but we don't want to pay the price for initializing + // just to silence a warning: 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); } @@ -987,11 +996,20 @@ 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 + // This warning is technically correct, but we don't want to pay the price for initializing + // just to silence a warning: 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;