function_base.hpp type-punned pointer warnings

I get a ton of warnings (well over 5000 in the code base I am compiling) from
function_base.hpp when compiling with gcc.
boost-1.46.0/include/boost/function/function_base.hpp:321: warning:
dereferencing type-punned pointer will break strict-aliasing rules
boost-1.46.0/include/boost/function/function_base.hpp:325: warning:
dereferencing type-punned pointer will break strict-aliasing rules
This has been a known problem for a very long time, and the work around is
quite simple. Replace
reinterpret_cast

"KSpam" wrote:
This has been a known problem for a very long time, and the work around is quite simple. Replace
reinterpret_cast
(&in_buffer.data)->~Functor(); with
functor_type* p = reinterpret_cast
(&in_buffer.data); p->~Functor();
Note however that this replacement causes a warning on MSVC ('p' not used), so it needs to be conditional, as in https://svn.boost.org/trac/boost/changeset/69251 Is there a ticket?

On Thursday 10 March 2011 09:59:35 Peter Dimov wrote:
"KSpam" wrote:
This has been a known problem for a very long time, and the work around is quite simple. Replace
reinterpret_cast
(&in_buffer.data)->~Functor(); with
functor_type* p = reinterpret_cast
(&in_buffer.data); p->~Functor(); Note however that this replacement causes a warning on MSVC ('p' not used), so it needs to be conditional, as in
I have run my patch on MSVC (8, 9, and 10) and GCC, and I do not recall seeing warnings from MSVC. Isn't p being used to call the destructor?
Is there a ticket?
I do not know. Respectfully, Justin

Justin wrote:
I have run my patch on MSVC (8, 9, and 10) and GCC, and I do not recall seeing warnings from MSVC. Isn't p being used to call the destructor?
The warning probably only appears when trying to call the destructor of a built-in type. I'm not sure whether Functor can be one in this context, so a direct replacement may be safe.

On Thursday 10 March 2011 09:59:35 Peter Dimov wrote:
Is there a ticket?
I see that #4538 was opened 7 months ago, and it is apparently a duplicate of #3780 from 15 months ago. https://svn.boost.org/trac/boost/ticket/4538 https://svn.boost.org/trac/boost/ticket/3780 Respectfully, Justin
participants (2)
-
KSpam
-
Peter Dimov