Open Pehrsons opened 1 year ago
@llvm/issue-subscribers-clang-static-analyzer
I don't think it's related to nested unions.
Here a simplified example demonstrating the root cause, which is that we model a call to ~Clazz()
to an object which never existed (no Clazz()
constructor was called). https://godbolt.org/z/KqKx13c1W
int sink;
struct Clazz {
Clazz() {
sink = 12 / 0; // no-warning bc. we never call this.
}
~Clazz() {
sink = 12 / 0; // For some reason we reach this from `main()`, which is really weird.
}
};
union U {
U() {}
~U() {}
Clazz t; // This is left uninitialized, hence any member of this is uninitialized!
};
int main() {
U u;
}
TL;DR https://godbolt.org/z/6nW54nTh5
Consider this bit:
clang-analyzer thinks
U<A<int>>::~U()
will implicitly callA<int>::~A()
, therefore accessing an uninitializedA<int>::b
:However, assembly shows there is no implicit
A<int>::~A()
called fromU<A<int>>::~U()
.