[Bug middle-end/105125] Bogus and Misleading Warning: Packed attribute is unnecessary.

pinskia at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 29 01:06:16 GMT 2022


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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
C testcase (moved over the GNU style attributes from C23 attributes though):
```
#include <stdint.h>

#define static_assert _Static_assert 
#define alignof _Alignof

struct A
{
    uint32_t i;
};

struct B
{
    uint64_t i;
};

struct C
{
    struct A a;
    struct B b;
};

struct D
{
    struct A a __attribute__((packed));
    struct B b;
};

struct E
{
    struct A a;
    struct B b __attribute__((packed));
};

struct F
{
    struct B b __attribute__((packed));
    struct A a;
};
static_assert((sizeof(struct A) ==  4) && (alignof(struct A) == 4));
static_assert((sizeof(struct B) ==  8) && (alignof(struct B) == 8));
static_assert((sizeof(struct C) == 16) && (alignof(struct C) == 8));
static_assert((sizeof(struct D) == 16) && (alignof(struct D) == 8));
static_assert((sizeof(struct E) == 12) && (alignof(struct E) == 4));
static_assert((sizeof(struct F) == 12) && (alignof(struct F) == 4));
```


More information about the Gcc-bugs mailing list