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

    <tr>
        <th>Summary</th>
        <td>
            `-Wunused-private-field` not reported for `[[gnu::warn_unused]]` annotated type when empty constructors are present
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:diagnostics,
            false-negative
      </td>
    </tr>

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

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

<pre>
    ```cpp
class [[gnu::warn_unused]] S1 {
public:
    S1() {}
};

class [[gnu::warn_unused]] S2 {
public:
    S2() = default;
};

class [[gnu::warn_unused]] S3 {
public:
    S3();
};

class [[gnu::warn_unused]] S4 {
};

class C {
public:
    C() {}

private:
 const S1 s1; // no warning
    const S2 s2; // warning
    const S3 s3; // no warning
    const S4 s4; // warning
};
```

```
<source>:25:14: warning: private field 's2' is not used [-Wunused-private-field]
   25 | const S2 s2; // warning
      |              ^
<source>:27:14: warning: private field 's4' is not used [-Wunused-private-field]
   27 |     const S4 s4; // warning
      | ^
```
https://godbolt.org/z/rjcEMzn96

If you change the `C` constructor to `= default` all are reported regardless of the other constructor.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJycVE1v4zgM_TX0hUggU_5IDj64SQPsYU9z2ONClmnHA9UyJDlF59cv5HjazE6DdhoENiw_Pj4-0lTeD_3IXEH-APkxUXM4W1d1g-NndeGkse1LBYW4_vU0gai1Ud7jEvDQjzPIGmT9rNz47zzOnlvIj5Af8VuKUD6AqKe5MYOOMFEjIn5LgXZA--V1eQRRx6uM0D9gp3vs9JNdHrHlTs0mrORfyCLvZZHXLF9nzlbm32MPd3IefrNN1JMbLirwCtJ29CEa71OQDwh0AjrhaDHmH8Z-JVphhJ5uYO9iJHr5CaoMffYu1Vt1P2foqvuXR3nwdnaaQT6CrCkHWacZyPqVR9a4FordwKZFoNITUImDx9EGjMZGzzf_XE3erPDNAo-WL3IpRygPn6ofF-QvP8gf31Fbfk5t9gW15auGj2x-U7yKvLH3HMLk44AsQb1tG2vC1roe6PQD6OS-68e_f4z74tqZvzp8sTPqsxp7xnBmhEIcoBBXEW7WwToMNh7ffmKFQGUMKsfoeLIucIuOe-Vaw96j7RYuG87sbpm2SVvJdi_3KuEqLfNdkYpdukvOVSOYil3btVmad_u201rrMuV9mnGT6q5JhooE5WJPUpRCpLttq9M8zdsd6VTotmTIBD-pwWyNuTzFipPB-5mrtBCUZYlRDRu_bD4ibdTSunZQ_Wh9GLQHIqADEHXKeN6M3KswXDge58fEVZF108y9h0yYwQf_licMwXDcm3daXIhlEF6N6qxb_Pxgaywmj6MNKgaFl4nx-cwj8tMUXm5d9UsfJseex5DMzlT_m4IhnOdmq-0T0CmqXm-bydnvrAPQabHKA51Wty4V_RcAAP__mAbNbg">