https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81234

            Bug ID: 81234
           Summary: [regression] flexible array member not at end of
                    ‘struct
           Product: gcc
           Version: 7.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Hi-Angel at yandex dot ru
  Target Milestone: ---

This code used to work prior to gcc-7.1 (it worked on 4.x, and — I just tested
— 6.3 works too, with a warning though):

        struct DataPacket {
                /* … */
                unsigned szdata;
                char data[];
        };

        struct AckPacket {
                DataPacket header;
                int a,b,c;
        };

        int main() { return 0; }

However gcc-7.1 bails out with:

        λ g++ test.cpp -o a                    
        test.cpp:4:12: error: flexible array member ‘DataPacket::data’ not at
end of ‘struct AckPacket’
          char data[];
                                ^
        test.cpp:9:6: note: next member ‘int AckPacket::a’ declared here
          int a,b,c; /* no data below */
                  ^
        test.cpp:7:8: note: in the definition of ‘struct AckPacket’
         struct AckPacket {

Imo the code is fine. Though I'm open to suggestions into a better design too.

Reply via email to