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

            Bug ID: 102288
           Summary: using .field = ({ static struct a a = {... }; &a; })
                    requires following field to be initialized
           Product: gcc
           Version: 11.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: cagney at sourceware dot org
  Target Milestone: ---

Created attachment 51438
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51438&action=edit
more examples (hopefully the version used for the above_

gcc --version
gcc (GCC) 11.2.1 20210728 (Red Hat 11.2.1-1)

Note the use of ({}) and static when initializing the field BA:

     1  struct a {
     2    unsigned a1;
     3  };
     4  
     5  #define A  ({ static const struct a a = { .a1 = 1, }; &a; })
     6  
     7  struct ba01 {
     8    const struct a *ba;
     9    int b0;
    10    int b1;
    11  };
    12  
    13  struct b0a1 {
    14    int b0;
    15    const struct a *ba;
    16    int b1;
    17  };
    18  
    19  struct b01a {
    20    int b0;
    21    int b1;
    22    const struct a *ba;
    23  };

    29    // complains that next field (.b0) isn't initialized
    30  
    31    {
    32      struct ba01 ba01 = {
    33        .ba = A,
    34        // .b0 = 0,
    35        // .b1 = 1,
    36      };
    37      use(&ba01);
    38    }


 gcc -Wall -Wextra -c unused.c
unused.c: In function ‘main’:
unused.c:36:5: warning: missing initializer for field ‘b0’ of ‘struct ba01’
[-Wmissing-field-initializers]
   36 |     };
      |     ^
unused.c:9:7: note: ‘b0’ declared here
    9 |   int b0;
      |       ^~

- just the next field needs to be initialized (not all)
- so, putting BA at the end avoids the problem
- so to does not using ({})

Reply via email to