[Bug c/41809] escaping address of packed field should trigger warning
tetra2005 at gmail dot com
gcc-bugzilla@gcc.gnu.org
Thu Oct 18 11:41:00 GMT 2012
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41809
Yuri Gribov <tetra2005 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |tetra2005 at gmail dot com
--- Comment #4 from Yuri Gribov <tetra2005 at gmail dot com> 2012-10-18 11:41:10 UTC ---
Gcc does warn (actually it even errs) if you try to pass unaligned variable by
reference but does not do this when you use pointers:
$ g++ -Wall -c pack_warns.cpp
pack_warns.cpp:22:9: error: cannot bind packed field 't->Test::x' to 'float&'
Also it'll fail to warn if you use #pragma pack instead of
__attribute__((packed)):
$ g++ -Wall -c -DUSE_PRAGMA pack_warns.cpp # Compiles wo warnings
Just wanted to mention that users frequently run into errors with unaligned
data (especially on targets where it really matters e.g. on ARM) so this might
be important issue.
More information about the Gcc-bugs
mailing list