xref: /llvm-project/clang/test/Analysis/Checkers/WebKit/ref-cntbl-base-virtual-dtor.cpp (revision 017675fff116c26bef7f0a389c983c909a3141fd)
1 // RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor -verify %s
2 
3 struct RefCntblBase {
refRefCntblBase4   void ref() {}
derefRefCntblBase5   void deref() {}
6 };
7 
8 struct Derived : RefCntblBase { };
9 // expected-warning@-1{{Struct 'RefCntblBase' is used as a base of struct 'Derived' but doesn't have virtual destructor}}
10 
11 struct DerivedWithVirtualDtor : RefCntblBase {
12 // expected-warning@-1{{Struct 'RefCntblBase' is used as a base of struct 'DerivedWithVirtualDtor' but doesn't have virtual destructor}}
~DerivedWithVirtualDtorDerivedWithVirtualDtor13   virtual ~DerivedWithVirtualDtor() {}
14 };
15 
16 // Confirm that the checker respects [[clang::suppress]]
17 struct [[clang::suppress]] SuppressedDerived : RefCntblBase { };
18 struct [[clang::suppress]] SuppressedDerivedWithVirtualDtor : RefCntblBase {
~SuppressedDerivedWithVirtualDtorSuppressedDerivedWithVirtualDtor19   virtual ~SuppressedDerivedWithVirtualDtor() {}
20 };
21 
22 // FIXME: Support attributes on base specifiers? Currently clang
23 // doesn't support such attributes at all, even though it knows
24 // how to parse them.
25 //
26 // struct SuppressedBaseSpecDerived : [[clang::suppress]] RefCntblBase { };
27 
28 template<class T>
29 struct DerivedClassTmpl : T { };
30 typedef DerivedClassTmpl<RefCntblBase> Foo;
31 
32 
33 
34 struct RandomBase {};
35 struct RandomDerivedClass : RandomBase { };
36 
37 
38 
39 struct FakeRefCntblBase1 {
40   private:
refFakeRefCntblBase141   void ref() {}
derefFakeRefCntblBase142   void deref() {}
43 };
44 struct Quiet1 : FakeRefCntblBase1 {};
45 
46 struct FakeRefCntblBase2 {
47   protected:
refFakeRefCntblBase248   void ref() {}
derefFakeRefCntblBase249   void deref() {}
50 };
51 struct Quiet2 : FakeRefCntblBase2 {};
52 
53 class FakeRefCntblBase3 {
ref()54   void ref() {}
deref()55   void deref() {}
56 };
57 struct Quiet3 : FakeRefCntblBase3 {};
58 struct Quiet4 : private RefCntblBase {};
59 class Quiet5 : RefCntblBase {};
60 
foo()61 void foo () {
62   Derived d;
63 }
64