Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Copy link
Copy link
Open
@sfc-gh-sgiesecke

Description

@sfc-gh-sgiesecke
Issue body actions

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.

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.