Skip to content

warn_cstruct_memaccess should not trigger inside constructors for otherwise trivially initializable types #156996

@ojhunt

Description

@ojhunt

We warn on this code, and variations of it, when gcc does not

  struct Object {
   int some_field;
   Object() { memset(this, 0, sizeof(*this); }
   Object(const Object&);
  };

I put together a general set of the cases at https://godbolt.org/z/5YYj1oxf9

Basically performing these operations within constructors of a type, as long as the reason for the type not being trivially_{whatever} is just its own constructors, not due to the object being polymorphic or some sub- or baseobject being non-trivial to copy or initialize.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions