Bug 68160 - Can bind packed field if it's packed with #pragma pack(push, 1)
Summary: Can bind packed field if it's packed with #pragma pack(push, 1)
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 5.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2015-10-30 13:47 UTC by Claudiu
Modified: 2020-05-20 22:01 UTC (History)
5 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 10.1.0, 11.0, 5.5.0, 6.4.0, 7.5.0, 8.3.0, 9.2.0
Last reconfirmed: 2020-05-19 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claudiu 2015-10-30 13:47:11 UTC
Consider the following code (http://coliru.stacked-crooked.com/a/b134364f7e775f87):

    #pragma pack(push, 1)
    struct foo1 {
        char a;
        int b;
    };
    #pragma pack(pop)
    
    struct foo2 {
        char a;
        int b;
    } __attribute__((__packed__, aligned(1) ));
    
    int main()
    {
        foo1 f1;
        foo2 f2;
        
        int& i1 = f1.b; // (1) ok
        int& i2 = f2.b; // (2) cannot bind packed field 'f2.foo2::b' to 'int&'
        
        return 0;
    }
    
(1) is valid, yet (2) produces the error. Shouldn't these behave exactly the same way, namely, (1) should also produce an error?
Comment 1 Eric Gallager 2017-08-25 14:54:52 UTC
Confirmed. I think this is related to bug 60972.
Comment 2 Eric Gallager 2019-03-11 18:53:50 UTC
cc-ing C++ FE maintainers
Comment 3 Eric Gallager 2019-12-11 05:22:11 UTC
(In reply to Eric Gallager from comment #1)
> Confirmed. I think this is related to bug 60972.

...and bug 92900 as well.
Comment 4 Martin Sebor 2020-05-19 20:22:13 UTC
Reconfirmed with GCC 11.