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

            Bug ID: 91423
           Summary: address-of-packed-member when taking packed struct
                    member by value
           Product: gcc
           Version: 9.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: anders at knatten dot org
  Target Milestone: ---

Compiling this with `-std=c++17 -Wall` on gcc 9.1.0:

```
#include <array>

struct __attribute__((__packed__))  Vec : std::array<std::size_t, 2>
{};

struct __attribute__((__packed__)) S
{
    Vec size;
};

void g()
{
    S s{};
    Vec size = s.size;
}
```

gives:

```
<source>:14:18: warning: taking address of packed member of 'S' may result in
an unaligned pointer value [-Waddress-of-packed-member]

   14 |     Vec size = s.size;
```

However, I'm not taking the address of the packed member, I'm taking it by
value. I think gcc shouldn't warn in this case.

Godbolt: https://godbolt.org/z/v4GZ6f

Reply via email to