Skip to content

in clang-analyzer, StackAddressEscape has problems with user-declared destructors #165900

@jmcclellan-figma

Description

@jmcclellan-figma

The following code:

struct A {
  int& x;
};

struct B {
  A a;
  ~B() {}
  B(A a) : a{a} {}
};

static B getA() {
  int x;
  return B{A{.x = x}};
}

incorrectly passes clang tidy with --checks=clang-analyzer-core.StackAddressEscape.

However, this very similar code correctly triggers the warning.

struct A {
  int& x;
};

struct B {
  A a;
  B(A a) : a{a} {}
};

static B getA() {
  int x;
  return B{A{.x = x}};
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions