From 9d0acd519573caed5d4c6aceb937073e8bc38052 Mon Sep 17 00:00:00 2001 From: Joakim Tosteberg Date: Wed, 4 Apr 2018 09:37:44 +0200 Subject: [PATCH] Use char type directly to avoid invalid aliasing in one more place --- include/boost/function/function_template.hpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/include/boost/function/function_template.hpp b/include/boost/function/function_template.hpp index c6bbd2d..177b60a 100644 --- a/include/boost/function/function_template.hpp +++ b/include/boost/function/function_template.hpp @@ -904,7 +904,9 @@ namespace boost { if (!f.empty()) { this->vtable = f.vtable; if (this->has_trivial_copy_and_destroy()) - this->functor = f.functor; + // Don't operate on storage directly since union type doesn't relax + // strict aliasing rules, despite of having member char type. + std::memcpy(this->functor.data, f.functor.data, sizeof(boost::detail::function::function_buffer)); else get_vtable()->base.manager(f.functor, this->functor, boost::detail::function::clone_functor_tag);