This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/36566] Cannot bind packed field
- From: "redi at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 18 Mar 2015 01:55:54 +0000
- Subject: [Bug c++/36566] Cannot bind packed field
- Auto-submitted: auto-generated
- References: <bug-36566-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36566
--- Comment #8 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Xiao Jia from comment #7)
> Adding "const" makes it compile. Is this the intended behavior or not?
Yes, of course. A const-reference causes a temporary to be created, you didn't
bind to the packed field:
Squeeze oj;
oj.s = 0;
const short& pit(oj.s);
oj.s = 1;
printf("%d %d", oj.s, pit);
This shows that oj.s and pit are not the same variable.