[Bug c++/47273] References to unaligned packed structure members not allowed

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Jan 14 16:15:00 GMT 2011


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.



More information about the Gcc-bugs mailing list