]> git.ipfire.org Git - thirdparty/gcc.git/commit
c-family: -Waddress-of-packed-member and casts
authorJason Merrill <jason@redhat.com>
Wed, 22 Nov 2023 18:20:58 +0000 (13:20 -0500)
committerJason Merrill <jason@redhat.com>
Wed, 13 Dec 2023 20:34:13 +0000 (15:34 -0500)
commitb7e4a4c626eeeb32c291d5bbbaa148c5081b6bfd
treecde073c8479e884ecb5dc8745b2afd56c0995c3f
parent7362543f00c9d3359d9377b800080fb421414ee5
c-family: -Waddress-of-packed-member and casts

-Waddress-of-packed-member, in addition to the documented warning about
actually taking the address of a packed member, also warns about casting
from a pointer to a TYPE_PACKED type to a pointer to a type with greater
alignment.

This wrongly warns if the source is a pointer to enum when -fshort-enums
is on, since that is also represented by TYPE_PACKED.

And there's already -Wcast-align to catch casting from pointer to less
aligned type (packed or otherwise) to pointer to more aligned type; even
apart from the enum problem, this seems like a somewhat arbitrary subset of
that warning.

So, this patch removes the undocumented type-based warning from
-Waddress-of-packed-member.  Some of the tests where the warning is
desirable I changed to use -Wcast-align=strict instead.  The ones that
require -Wno-incompatible-pointer-types I just removed.

gcc/c-family/ChangeLog:

* c-warn.cc (check_address_or_pointer_of_packed_member):
Remove warning based on TYPE_PACKED.

gcc/testsuite/ChangeLog:

* c-c++-common/Waddress-of-packed-member-1.c: Don't expect
a warning on the cast cases.
* c-c++-common/pr51628-35.c: Use -Wcast-align=strict.
* g++.dg/warn/Waddress-of-packed-member3.C: Likewise.
* gcc.dg/pr88928.c: Likewise.
* gcc.dg/pr51628-20.c: Removed.
* gcc.dg/pr51628-21.c: Removed.
* gcc.dg/pr51628-25.c: Removed.
gcc/c-family/c-warn.cc
gcc/testsuite/c-c++-common/Waddress-of-packed-member-1.c
gcc/testsuite/c-c++-common/pr51628-35.c
gcc/testsuite/g++.dg/warn/Waddress-of-packed-member3.C
gcc/testsuite/gcc.dg/pr51628-20.c [deleted file]
gcc/testsuite/gcc.dg/pr51628-21.c [deleted file]
gcc/testsuite/gcc.dg/pr51628-25.c [deleted file]
gcc/testsuite/gcc.dg/pr88928.c