[Bug c/47273] References to unaligned packed structure members not allowed
waldemarbancewicz at ruggedcom dot com
gcc-bugzilla@gcc.gnu.org
Fri Jan 14 13:50:00 GMT 2011
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47273
--- Comment #2 from Waldemar Valdas Bancewicz <waldemarbancewicz at ruggedcom dot com> 2011-01-14 13:42:03 UTC ---
Consider the following program test.c:
#include <stdio.h>
struct s {
char a;
int b;
int* GetValp() { return &b; }
int& GetValr() { return b; }
} __attribute__((packed));
int main() {
struct s s1;
*(s1.GetValp()) = 150;
s1.GetValr() = 5;
printf("%d\n", s1.b);
}
When trying to compile we get the following error message:
waldemarbancewicz@waldemarbancewicz:~/tmp$ g++ -o test test.c
test.c: In member function ‘int& s::GetValr()’:
test.c:7: error: cannot bind packed field ‘((s*)this)->s::b’ to ‘int&’
More information about the Gcc-bugs
mailing list