[clang] [analysis] Do not destruct fields of unions (PR #122330)
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 3 07:45:15 PST 2025
================
@@ -377,3 +377,27 @@ void directUnknownSymbol() {
}
}
+
+void testUnionDtor() {
+ static int unionDtorCalled;
+ InlineDtor::cnt = 0;
+ InlineDtor::dtorCalled = 0;
+ unionDtorCalled = 0;
+ {
+ union UnionDtor {
+ InlineDtor kind1;
+ char kind2;
+ ~UnionDtor() { unionDtorCalled++; }
+ };
+ UnionDtor u1{.kind1{}};
+ UnionDtor u2{.kind2{}};
+ auto u3 = new UnionDtor{.kind1{}};
+ auto u4 = new UnionDtor{.kind2{}};
+ delete u3;
+ delete u4;
+ }
+
+ clang_analyzer_eval(unionDtorCalled == 4); // expected-warning {{TRUE}}
+ clang_analyzer_eval(InlineDtor::dtorCalled != 4); // expected-warning {{TRUE}}
----------------
steakhal wrote:
```suggestion
```
The next line checks the equality of the expected value. That means this assertion is redundant.
https://github.com/llvm/llvm-project/pull/122330
More information about the cfe-commits
mailing list