102 lines · cpp
1// RUN: %clang_analyze_cc1 -analyzer-checker=webkit.NoUncountedMemberChecker -verify %s2 3#include "mock-types.h"4#include "mock-system-header.h"5 6namespace members {7 struct Foo {8 private:9 RefCountable* a = nullptr;10// expected-warning@-1{{Member variable 'a' in 'members::Foo' is a raw pointer to ref-countable type 'RefCountable'}}11 12 [[clang::suppress]]13 RefCountable* a_suppressed = nullptr;14 15 protected:16 RefPtr<RefCountable> b;17 18 public:19 RefCountable silenceWarningAboutInit;20 RefCountable& c = silenceWarningAboutInit;21// expected-warning@-1{{Member variable 'c' in 'members::Foo' is a reference to ref-countable type 'RefCountable'}}22 Ref<RefCountable> d;23 };24 25 template<class T>26 struct FooTmpl {27 T* a;28// expected-warning@-1{{Member variable 'a' in 'members::FooTmpl<RefCountable>' is a raw pointer to ref-countable type 'RefCountable'}}29 };30 31 void forceTmplToInstantiate(FooTmpl<RefCountable>) {}32 33 struct [[clang::suppress]] FooSuppressed {34 private:35 RefCountable* a = nullptr;36 };37} // members38 39namespace unions {40 union Foo {41 RefCountable* a;42 // expected-warning@-1{{Member variable 'a' in 'unions::Foo' is a raw pointer to ref-countable type 'RefCountable'}}43 RefPtr<RefCountable> b;44 Ref<RefCountable> c;45 };46 47 template<class T>48 union FooTmpl {49 T* a;50 // expected-warning@-1{{Member variable 'a' in 'unions::FooTmpl<RefCountable>' is a raw pointer to ref-countable type 'RefCountable'}}51 };52 53 void forceTmplToInstantiate(FooTmpl<RefCountable>) {}54} // unions55 56namespace ignore_system_header {57 58void foo(RefCountable* t) {59 MemberVariable<RefCountable> var { t };60 var.obj->method();61}62 63} // ignore_system_header64 65namespace ignore_non_ref_countable {66 struct Foo {67 };68 69 struct Bar {70 Foo* foo;71 };72} // ignore_non_ref_countable73 74namespace checked_ptr_ref_ptr_capable {75 76 RefCountableAndCheckable* provide();77 void foo() {78 CheckedPtr<RefCountableAndCheckable> foo = provide();79 }80 81} // checked_ptr_ref_ptr_capable82 83namespace ptr_to_ptr_to_ref_counted {84 85 struct List {86 RefCountable** elements;87 // expected-warning@-1{{Member variable 'elements' in 'ptr_to_ptr_to_ref_counted::List' contains a raw pointer to ref-countable type 'RefCountable'}}88 };89 90 template <typename T>91 struct TemplateList {92 T** elements;93 // expected-warning@-1{{Member variable 'elements' in 'ptr_to_ptr_to_ref_counted::TemplateList<RefCountable>' contains a raw pointer to ref-countable type 'RefCountable'}}94 };95 TemplateList<RefCountable> list;96 97 struct SafeList {98 RefPtr<RefCountable>* elements;99 };100 101} // namespace ptr_to_ptr_to_ref_counted102