[Bug c++/105125] New: Bogus and Misleading Warning: Packed attribute is unnecessary.
Kimon.Hoffmann at lawo dot com
gcc-bugzilla@gcc.gnu.org
Fri Apr 1 13:34:25 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105125
Bug ID: 105125
Summary: Bogus and Misleading Warning: Packed attribute is
unnecessary.
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: Kimon.Hoffmann at lawo dot com
Target Milestone: ---
GCC erroneously declares a packed attribute on a struct member as unnecessary,
while it clearly isn't.
Reproducer:
---------- 8< ----------
#include <cstdint>
struct A
{
std::uint32_t i;
};
struct B
{
std::uint64_t i;
};
struct C
{
A a;
B b;
};
struct D
{
A a [[gnu::packed]];
B b;
};
struct E
{
A a;
B b [[gnu::packed]];
};
struct F
{
B b [[gnu::packed]];
A a;
};
static_assert((sizeof(A) == 4) && (alignof(A) == 4));
static_assert((sizeof(B) == 8) && (alignof(B) == 8));
static_assert((sizeof(C) == 16) && (alignof(C) == 8));
static_assert((sizeof(D) == 16) && (alignof(D) == 8));
static_assert((sizeof(E) == 12) && (alignof(E) == 4));
static_assert((sizeof(F) == 12) && (alignof(F) == 4));
---------- >8 ----------
Invocation: cat test.cpp | x86_64-linux-gnu-g++ -xc++ -std=c++17 -Wpacked -c -o
/dev/null -
Observed behavior:
<stdin>:21:7: warning: packed attribute is unnecessary for ‘D::a’
[-Wattributes]
<stdin>:33:7: warning: packed attribute is unnecessary for ‘F::b’
[-Wattributes]
Expected behaviur:
While the warning referring to line 21 is correct, the warning referring to
line 33 isn't, and thus no message is expected.
Please note that this report describes the same behavior as report #59220, but
is more generally applicable, as the aforementioned report uses an explicitly
overaligned type, and might thus give the false impression that overalignment
is a required prerequisite for the issue to.
More information about the Gcc-bugs
mailing list