<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/96726>96726</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[clang][libc++] std::addressof silences -Waddress-of-packed-member diagnostics.
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang,
libc++
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
BlamKiwi
</td>
</tr>
</table>
<pre>
We recently had a bug where we were inadvertently taking an address of a packed member inside some template code. `std::addressof` appears to prevent `-Waddress-of-packed-member` diagnostics. It would be good if clang somehow treated `std::addressof(x)` as equivalent to `&a` for the purposes of providing diagnostics for `-Waddress-of-packed-member`.
[Godbolt minimal example](https://godbolt.org/z/P613roxn5)
In general, it looks like clang doesn't diagnose when an lvalue reference is taken to an unaligned member. For our use-case, it would be nice if -Waddress-of-packed-member would diagnose all lvalue references to unaligned members. Although I could understand if just adding a heuristic for `std::addressof` is more palatable.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEVE2PnDgQ_TXmUmoERQPTBw7TabEa7WVvORe4AGeMzfqje7K_fmW6k50kmo1kwYHyq_fqvYK8V7Nh7kR9FvUloxgW67qzpvVPdVPZYOXX7jOD45FN0F9hIQkEQ5zhtrBjuKXjGJQheWUX7lWBXpWZgQyQlI69BzsBwUbjK0tYeR3YgTJeSQZvV4bA66YpMIxWcg6iKXyQonoW1fMDwU6iKYC2jcl5CBY2x1c2IdUePj-KDnY63Jsc7k3SHaloNtYHNfoc4CXAzUYtYWCYrZWgJhg1mXknstgbBMcUWH5AAp_eBJ52Lh7476iupBONYNMFgQ2lb5N1EBaGLbrNet71b85elUxzecdor_ythlwUF1E8P571-Q8rB6sDrMqolTTwG62bZlFfBD4tIWw-0cZeYD_fS3PrZoH9PwL7v5qycvbN1EnHO9wXAzMbdqQFfgIVQFv76kGrV35MSFr2RmAbvinglAKTfNZX0jHlZGLHZmRQPqWATRoMGYiGdEraN_dz6K0DGx1Ez4eRPD-afjfHqIQywceDedR-50Ja_8Jjj8rPzX0OzzosNs4LvMC4o0Qj2flAZk_El-hDyu6eYlg4OpXs2t36MJzKw2odw0aaAg2af7Atk10lT9WJMu7KtjxVbXls22zpmLGqq3HE6TRNDXJbDFNRnpqmxHFEbjLVYYHHosGmqMqybPPT-NQcq5oaeaSB21ocC15J6Vzr65qczpT3kbtT02KTaRpY-33DEXcjBaLATwJRq2EUeN4Ppv13XYI4DHH24lho5YP_DzSooPc_xR2kvoj6_A6hvsCvcwGv9N2H__Hxhw3NotPdTxlWYYlDPtpVYJ_oPF6HzdkvPAaB_S7YC-zvmq8d_hsAAP__f9qeKg">