Opened 12 years ago
Closed 12 years ago
#4538 closed Bugs (fixed)
Warning: dereferencing type-punned pointer will break strict-aliasing rules
Reported by: | Owned by: | No-Maintainer | |
---|---|---|---|
Milestone: | Boost 1.44.0 | Component: | function |
Version: | Boost 1.44.0 | Severity: | Problem |
Keywords: | Cc: |
Description
Hi,
compiling the attached example with gcc-4.4.3 (Ubuntu 10.4, 64bit) with
-Wall -O3
leads to a long warning message (second attachment), culminating in
boost/1.44/include/boost/function/function_base.hpp:321: warning: dereferencing type-punned pointer will break strict-aliasing rules boost/1.44/include/boost/function/function_base.hpp:325: warning: dereferencing type-punned pointer will break strict-aliasing rules
A way to avoid this warning is been suggested by Justin in the boost-users mailing list:
http://lists.boost.org/boost-users/2010/08/61564.php
Replace:
reinterpret_cast<functor_type*>(&in_buffer.data)->~Functor();
with:
functor_type* p = reinterpret_cast<functor_type*>(&in_buffer.data); p->~Functor();
(Second line with out_buffer, respectively)
As noted by Emil Dotchevski in the thread on boost-users, it seems questionable why splitting up the original lines can get rid of the warning. So maybe a ticket should be filed for gcc by someone more knowledgeable than me.
Attachments (2)
Change History (8)
by , 12 years ago
Attachment: | Spirit.cpp added |
---|
comment:2 by , 12 years ago
When will the patch be applied? This warning is very annoying to me because it causes pages of follow-up template errors. Is the suggested patch not considered a good fix to the problem?
comment:3 by , 12 years ago
Owner: | changed from | to
---|
Not sure who is maintaining function these days, let's try to volunteer Daniel James. :-)
comment:4 by , 12 years ago
May be safer is to replace reinterpret_cast<functor_type*>(something) by static_cast<functor_type*>(static_cast<void*>(something))?
comment:6 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Source code leading to said warning