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}};
}