<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/140240>140240</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
false positives of bugprone-sizeof-expression with a plain template type argument
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang-tidy,
false-positive
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
sfc-gh-sgiesecke
</td>
</tr>
</table>
<pre>
When a template like
```
template <typename T>
void unalignedStore(void* const dst, const T& src) noexcept {
std::memcpy(dst, &src, sizeof(T));
}
```
is instantiated with `Foo*` such that `Foo` is an aggregate, then this produces a diagnostic of `bugprone-sizeof-expression`:
```
error: suspicious usage of 'sizeof(A*)' on pointer-to-aggregate type; did you mean 'sizeof(A)'?
```
I'd say that it generally makes sense to emit a warning if the sizeof expression is of the form `sizeof(T)` where `T` is a template type argument.
In addition, even if it makes sense, the diagnostic is not too helpful, as it doesn't mention the context of instantiation or the actual template type argument. `A*/A` is just a placeholder, which is generally confusing.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJx0VE1v8ygQ_jX4MnLk4I_EBx_cdiPteSvtGcPY5i0Gixmnzf76FUnavG-lSkhRGJ6Z5wOsiOzkETtRP4n6JVMbzyF2NOp8mnOaLBLqN8yGYC7dvzN6UMC4rE4xgrNvKIpeNMV9Ff1XTZTPfFnRqwXhVZR_iaI_B2tg88qlieYfDhGFPKZdIXvQwRODIRby-f7nVcgGKGohW_ABPzSuDOLwJIoegNiIshdlv-Ci14uQxztWyOaKeQay_2EYhTy-CtmmVSaoOLx8I20JrCdWnq1iNPBueQbRFKcQhEwngTY9A8-KP7ebAiyB8qCmKeKkGNNATgbxbAnWGMymkUCBsWrygdhqCGPCD9u0xuAxv_HL8WONSGSDT3TK_hs7jDFEUfZAG61W27ARbKQmvLaThy-VfSKbhB4geFiD9Ywx55B_cYQUiSifwFgDl7DBgsp_75EaiPL0jYUo-r-FPBggdbk5YRkm9BiVcxdY1BsSEHpC4AC4WAYF7yp66yewY7Lmngc89CYPw602hrhAcufP0JoC3meMmCqvn64_bmDSAypO24Ked3eaHpQxlpOf8hnwjD4RsPw7yXtav4djCXxg4BBgRreOm0uHFCWkCUheyANDGpSYJ7AOnvGDk4TH_UnFEK91pXlT7ie2SdItslN_V_Zro2Tb6pTGOTiDMVF4n62eU_lhtw5-3Mj6aZeZrjRt2aoMu_2hOpRtXeyLbO7GtmyGfV1VdT1UbauH476qhmMj67opG6ky28lC1kW9b_b7stgXu8GUx0ZWqMu2PTTNKKoCF2XdzrnzsgtxyizRht2-KmRVZE4N6Oj64ZBSO-WnnK25CCmFfBZSjsoR5msgy_aMabt-yWKXmuXDNpGoCmeJ6dGeLTvsrjj4xF0vyM8v5vZWr5ZZ_4PT2RZdNzOvlB6XPAl5mizP27DTYRHylObff_I1hl-oWcjTVSsJebrLPXfy_wAAAP__ix2vUw">