39 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-inlining=destructors -verify -std=c++11 %s2// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -analyzer-config c++-inlining=destructors -verify -std=c++17 %s3 4void clang_analyzer_eval(bool);5 6struct InlineDtor {7 static int cnt;8 static int dtorCalled;9 ~InlineDtor() {10 ++dtorCalled;11 }12};13 14int InlineDtor::cnt = 0;15int InlineDtor::dtorCalled = 0;16 17void testUnionDtor() {18 static int unionDtorCalled;19 InlineDtor::cnt = 0;20 InlineDtor::dtorCalled = 0;21 unionDtorCalled = 0;22 {23 union UnionDtor {24 InlineDtor kind1;25 char kind2;26 ~UnionDtor() { unionDtorCalled++; }27 };28 UnionDtor u1{.kind1{}};29 UnionDtor u2{.kind2{}};30 auto u3 = new UnionDtor{.kind1{}};31 auto u4 = new UnionDtor{.kind2{}};32 delete u3;33 delete u4;34 }35 36 clang_analyzer_eval(unionDtorCalled == 4); // expected-warning {{TRUE}}37 clang_analyzer_eval(InlineDtor::dtorCalled == 0); // expected-warning {{TRUE}}38}39