Opened 12 years ago

Closed 12 years ago

#4538 closed Bugs (fixed)

Warning: dereferencing type-punned pointer will break strict-aliasing rules

Reported by: Roland Bock <rbock@…> 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)

Spirit.cpp (557 bytes ) - added by Roland Bock <rbock@…> 12 years ago.
Source code leading to said warning
log (11.1 KB ) - added by Roland Bock <rbock@…> 12 years ago.
Warning messages

Download all attachments as: .zip

Change History (8)

by Roland Bock <rbock@…>, 12 years ago

Attachment: Spirit.cpp added

Source code leading to said warning

by Roland Bock <rbock@…>, 12 years ago

Attachment: log added

Warning messages

comment:1 by sergey.belyashov@…, 12 years ago

this is dublicate of Ticket #3780

comment:2 by anonymous, 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 Peter Dimov, 12 years ago

Owner: changed from Douglas Gregor to Daniel James

Not sure who is maintaining function these days, let's try to volunteer Daniel James. :-)

comment:4 by sergey.belyashov@…, 12 years ago

May be safer is to replace reinterpret_cast<functor_type*>(something) by static_cast<functor_type*>(static_cast<void*>(something))?

comment:5 by Daniel James, 12 years ago

Owner: changed from Daniel James to No-Maintainer

No thanks.

comment:6 by Peter Dimov, 12 years ago

Resolution: fixed
Status: newclosed

This is fixed by [62621] in trunk, and by [70361] in release.

Note: See TracTickets for help on using tickets.