Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(972)

Side by Side Diff: tools/clang/plugins/tests/base_refcounted.h

Issue 10407057: Optionally check base classes for refcounting issues (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef BASE_REFCOUNTED_H_ 5 #ifndef BASE_REFCOUNTED_H_
6 #define BASE_REFCOUNTED_H_ 6 #define BASE_REFCOUNTED_H_
7 7
8 namespace base { 8 namespace base {
9 9
10 template <typename T> 10 template <typename T>
11 class RefCounted { 11 class RefCounted {
12 public: 12 public:
13 RefCounted() {} 13 RefCounted() {}
14 protected:
14 ~RefCounted() {} 15 ~RefCounted() {}
15 }; 16 };
16 17
17 template <typename T> 18 template <typename T>
18 class RefCountedThreadSafe { 19 class RefCountedThreadSafe {
19 public: 20 public:
20 RefCountedThreadSafe() {} 21 RefCountedThreadSafe() {}
22 protected:
21 ~RefCountedThreadSafe() {} 23 ~RefCountedThreadSafe() {}
22 }; 24 };
23 25
24 } // namespace base 26 } // namespace base
25 27
26 // Ignore classes whose inheritance tree ends in WebKit's RefCounted base 28 // Ignore classes whose inheritance tree ends in WebKit's RefCounted base
27 // class. Though prone to error, this pattern is very prevalent in WebKit 29 // class. Though prone to error, this pattern is very prevalent in WebKit
28 // code, so do not issue any warnings. 30 // code, so do not issue any warnings.
29 namespace WebKit { 31 namespace WebKit {
30 32
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 }; 113 };
112 114
113 // Unsafe-but-ignored; should not have errors. 115 // Unsafe-but-ignored; should not have errors.
114 class WebKitDerivedPublicDtorInHeader 116 class WebKitDerivedPublicDtorInHeader
115 : public WebKitPublicDtorInHeader { 117 : public WebKitPublicDtorInHeader {
116 public: 118 public:
117 WebKitDerivedPublicDtorInHeader() {} 119 WebKitDerivedPublicDtorInHeader() {}
118 ~WebKitDerivedPublicDtorInHeader() {} 120 ~WebKitDerivedPublicDtorInHeader() {}
119 }; 121 };
120 122
123 class APublicInterface {
124 public:
125 virtual ~APublicInterface() {}
126 virtual void DoFoo() = 0;
127 };
128
129 // Unsafe. "ImplementsAPublicInterface* foo" can be deleted via
130 // "delete (APublicInterface*)foo;".
131 class ImplementsAPublicInterface
132 : public APublicInterface,
133 public base::RefCounted<ImplementsAPublicInterface> {
134 public:
135 virtual void DoFoo() override {}
136
137 protected:
138 virtual ~ImplementsAPublicInterface() {}
139
140 private:
141 friend class base::RefCounted<ImplementsAPublicInterface>;
142 };
143
144 class AnImplicitInterface {
145 public:
146 virtual void DoBar() {}
147 };
148
149 // Unsafe.
150 class ImplementsAnImplicitInterface
151 : public AnImplicitInterface,
152 public base::RefCounted<ImplementsAnImplicitInterface> {
153 public:
154 virtual void DoBar() override {}
155
156 private:
157 friend class base::RefCounted<ImplementsAnImplicitInterface>;
158 ~ImplementsAnImplicitInterface() {}
159 };
160
161 // Safe. Private inheritance does not expose the base destructor.
162 class PrivatelyImplementsAPublicInterface
163 : private APublicInterface,
164 public base::RefCounted<PrivatelyImplementsAPublicInterface> {
165 public:
166 virtual void DoFoo() override {}
167
168 private:
169 friend class base::RefCounted<PrivatelyImplementsAPublicInterface>;
170 virtual ~PrivatelyImplementsAPublicInterface() {}
171 };
172
173 // Unsafe.
174 class BaseInterface {
175 public:
176 virtual ~BaseInterface() {}
177 virtual void DoFoo() {}
178 };
179 class DerivedInterface : public BaseInterface {
180 protected:
181 virtual ~DerivedInterface() {}
182 };
183 class SomeOtherInterface {
184 public:
185 virtual ~SomeOtherInterface() {}
186 virtual void DoBar() {}
187 };
188 class RefcountedType : public base::RefCounted<RefcountedType> {
189 protected:
190 ~RefcountedType() {}
191 private:
192 friend class base::RefCounted<RefcountedType>;
193 };
194 class UnsafeInheritanceChain
195 : public DerivedInterface,
196 public SomeOtherInterface,
197 public RefcountedType {
198 public:
199 // DerivedInterface
200 virtual void DoFoo() override {}
201
202 // SomeOtherInterface
203 virtual void DoBar() override {}
204
205 protected:
206 virtual ~UnsafeInheritanceChain() {}
207 };
208
121 #endif // BASE_REFCOUNTED_H_ 209 #endif // BASE_REFCOUNTED_H_
OLDNEW
« no previous file with comments | « tools/clang/plugins/FindBadConstructs.cpp ('k') | tools/clang/plugins/tests/base_refcounted.flags » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698