This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/36566] Cannot bind packed field


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]