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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |msebor at gcc dot gnu.org

--- Comment #7 from Martin Sebor <msebor at gcc dot gnu.org> ---
Starting with version 9 GCC diagnoses both calls in the test case in comment #0
(the test case with #pragma pack in comment #3 is not diagnosed):

$ cat pr41809.c && gcc -O2 -S -Wall pr41809.c
void f(int *);

struct s {
    int x;
    char c;
} __attribute__((__packed__));

struct s A[10];

int main(void)
{
    for (int i = 0; i != sizeof(A)/sizeof(A[0]); ++i) {
        f(&A[i].x);
        f((int*)(char*)&A[i].x);
    }    
}
pr41809.c: In function ‘main’:
pr41809.c:13:11: warning: taking address of packed member of ‘struct s’ may
result in an unaligned pointer value [-Waddress-of-packed-member]
   13 |         f(&A[i].x);
      |           ^~~~~~~
pr41809.c:14:11: warning: taking address of packed member of ‘struct s’ may
result in an unaligned pointer value [-Waddress-of-packed-member]
   14 |         f((int*)(char*)&A[i].x);
      |           ^~~~~~~~~~~~~~~~~~~~

Reply via email to