Skip to content

false positives of bugprone-sizeof-expression with a plain template type argument #140240

Open
@sfc-gh-sgiesecke

Description

@sfc-gh-sgiesecke

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 does not make 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions