Open
Description
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.