http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59220

            Bug ID: 59220
           Summary: bogus warning: packed attribute is unnecessary on an
                    overaligned char
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gmail dot com

GCC 4.8.2 and prior incorrectly issue a warning for one-byte struct members
declared with the packed attribute when the member is of an over-aligned type.
The program below shows that the attribute is not unnecessary (it changes the
alignment of the struct member and the whole struct).

$ cat v.c && gcc -Wpacked v.c && ./a.out
extern int printf (const char*, ...);

typedef char C __attribute__ ((aligned (4)));

struct S {
   C c __attribute__ ((packed));
};

int main (void) {
    struct S s;
    printf ("%zu %zu %zu\n",
             __alignof__ (s), __alignof__ (s.c), __alignof__ (C));
    return 0;
} 
v.c:6:6: warning: packed attribute is unnecessary for ā€˜c’ [-Wattributes]
    C c __attribute__ ((packed));
      ^
1 1 4

Reply via email to