| 1 |
// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.RefCntblBaseVirtualDtor -verify %s |
| 2 |
|
| 3 |
namespace WTF { |
| 4 |
|
| 5 |
class NoVirtualDestructorBase { }; |
| 6 |
|
| 7 |
}; |
| 8 |
|
| 9 |
using WTF::NoVirtualDestructorBase; |
| 10 |
|
| 11 |
struct RefCntblBase { |
| 12 |
void ref() {} |
| 13 |
void deref() {} |
| 14 |
}; |
| 15 |
|
| 16 |
struct Derived : RefCntblBase { }; |
| 17 |
// expected-warning@-1{{Struct 'RefCntblBase' is used as a base of struct 'Derived' but doesn't have virtual destructor}} |
| 18 |
|
| 19 |
struct DerivedWithVirtualDtor : RefCntblBase { |
| 20 |
// expected-warning@-1{{Struct 'RefCntblBase' is used as a base of struct 'DerivedWithVirtualDtor' but doesn't have virtual destructor}} |
| 21 |
virtual ~DerivedWithVirtualDtor() {} |
| 22 |
}; |
| 23 |
|
| 24 |
// Confirm that the checker respects [[clang::suppress]] |
| 25 |
struct [[clang::suppress]] SuppressedDerived : RefCntblBase { }; |
| 26 |
struct [[clang::suppress]] SuppressedDerivedWithVirtualDtor : RefCntblBase { |
| 27 |
virtual ~SuppressedDerivedWithVirtualDtor() {} |
| 28 |
}; |
| 29 |
|
| 30 |
class ClassWithoutVirtualDestructor : public NoVirtualDestructorBase { |
| 31 |
public: |
| 32 |
void ref() const; |
| 33 |
void deref() const; |
| 34 |
}; |
| 35 |
|
| 36 |
class DerivedClassWithoutVirtualDestructor : public ClassWithoutVirtualDestructor { |
| 37 |
}; |
| 38 |
|
| 39 |
// FIXME: Support attributes on base specifiers? Currently clang |
| 40 |
// doesn't support such attributes at all, even though it knows |
| 41 |
// how to parse them. |
| 42 |
// |
| 43 |
// struct SuppressedBaseSpecDerived : [[clang::suppress]] RefCntblBase { }; |
| 44 |
|
| 45 |
template<class T> |
| 46 |
struct DerivedClassTmpl : T { }; |
| 47 |
typedef DerivedClassTmpl<RefCntblBase> Foo; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
struct RandomBase {}; |
| 52 |
struct RandomDerivedClass : RandomBase { }; |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
struct FakeRefCntblBase1 { |
| 57 |
private: |
| 58 |
void ref() {} |
| 59 |
void deref() {} |
| 60 |
}; |
| 61 |
struct Quiet1 : FakeRefCntblBase1 {}; |
| 62 |
|
| 63 |
struct FakeRefCntblBase2 { |
| 64 |
protected: |
| 65 |
void ref() {} |
| 66 |
void deref() {} |
| 67 |
}; |
| 68 |
struct Quiet2 : FakeRefCntblBase2 {}; |
| 69 |
|
| 70 |
class FakeRefCntblBase3 { |
| 71 |
void ref() {} |
| 72 |
void deref() {} |
| 73 |
}; |
| 74 |
struct Quiet3 : FakeRefCntblBase3 {}; |
| 75 |
struct Quiet4 : private RefCntblBase {}; |
| 76 |
class Quiet5 : RefCntblBase {}; |
| 77 |
|
| 78 |
void foo () { |
| 79 |
Derived d; |
| 80 |
} |