[C++-sig] type-punning in boost python code.

Philipp Thomas pth at suse.de
Fri Nov 25 18:16:15 CET 2005

our gcc 4.1 also analyses C++ code for violation of the C/C++ aliasing
rules (mainline doesn't do so yet). For the code in boost 1.33.1 I get 

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

for the following files:

 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/long.cpp: 12,19, 26
 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/dict.cpp: 32
 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/str.cpp: 12
 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/object/class.cpp:543, 553
 /usr/src/packages/BUILD/boost_1_33_1/libs/python/build/../src/list.cpp: 15

as our package build system treats this warning as an error, I will use -fno-strict-aliasing
for gcc as I'm not familiar with that code and I want to get the package built.

For boost you should also consider either using said gcc switch or fix the
code to not break strict-aliasing rules. I'd recommend doing the latter as
switching off aliasing analysis will inhibit some optimisations.


More information about the Cplusplus-sig mailing list