This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/47273] References to unaligned packed structure members not allowed
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 14 Jan 2011 16:02:09 +0000
- Subject: [Bug c++/47273] References to unaligned packed structure members not allowed
- Auto-submitted: auto-generated
- References: <bug-47273-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47273
--- Comment #8 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-01-14 16:02:06 UTC ---
It works with
typedef int T __attribute__((aligned(1)));
struct s {
T a;
T& GetValr() { return a; }
} __attribute__((packed));
int main() {
struct s s1;
s1.GetValr() = 5;
}
so it's probably to guard you against crashes on targets that do
not support unaligned accesses (*(int&) is aligned but s1.b is not).
Note that the above will still not do what is necessary for such
targets.
The pointer case is probably supported for legacy reasons.