<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/62353>62353</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            regression: -Wpacked now contradicts the reality
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          stsp
      </td>
    </tr>
</table>

<pre>
    ```
#include <stdio.h>
#include <stdint.h>

template<typename T>
class SymWrp : public T {
public:
    SymWrp() = default;
} __attribute__((packed));

struct dhdr {
  uint16_t dh_attr;
};

struct lol {
  unsigned char _l;
  SymWrp<struct dhdr> _n;
  unsigned char _nj;
} __attribute__((packed));

int main()
{
    printf("%zi\n", sizeof(struct lol));
    return 0;
}
```

Lets build with clang-15, which behaves correctly:
```
$ clang++-15 -Wall -Wpacked pod.cpp 
pod.cpp:5:7: warning: packed attribute is unnecessary for 'SymWrp<dhdr>' [-Wpacked]
class SymWrp : public T {
      ^
1 warning generated.
```
If we follow the warning and remove the
packed attribute from SymWrp, we get
no warning and a properly working program.

Now with clang-16 you get the same warning
when compiling the original, but after removing
the packed attribute from SymWrp you get this:
```
$ clang++-16 -Wall -Wpacked -Werror=packed-non-pod pod.cpp 
pod.cpp:16:23: error: not packing field '_n' as it is non-POD for the purposes of layout [-Werror,-Wpacked-non-pod]
  SymWrp<struct dhdr> _n;
                      ^
pod.cpp:14:8: warning: packed attribute is unnecessary for 'lol' [-Wpacked]
struct lol {
       ^
1 warning and 1 error generated.
```

So an attempt to follow the valid Wpacked
suggestion, now leads to the Wpacked-non-pod
warning and results in a bad code generated.

The problem was introduced with https://github.com/llvm/llvm-project/commit/277123376ce08c98b07c154bf83e4092a5d4d3c6
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJykVt1u4zYTfRr6ZmBDIq0fX_jCiTfAB3xoC-wCuTQociRxlyIFkor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