This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/41809] escaping address of packed field should trigger warning
- From: "tetra2005 at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 18 Oct 2012 11:41:10 +0000
- Subject: [Bug c/41809] escaping address of packed field should trigger warning
- Auto-submitted: auto-generated
- References: <bug-41809-4@http.gcc.gnu.org/bugzilla/>
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.