[Session restore] Rename group name Enabled to Restore.
[chromium-blink-merge.git] / tools / clang / plugins / tests / base_refcounted.h
blob4a489ee44e41761d124a99c9939080587f6faa40
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
3 // found in the LICENSE file.
5 #ifndef BASE_REFCOUNTED_H_
6 #define BASE_REFCOUNTED_H_
8 namespace base {
10 template <typename T>
11 class RefCounted {
12 public:
13 RefCounted() {}
14 protected:
15 ~RefCounted() {}
18 template <typename T>
19 class RefCountedThreadSafe {
20 public:
21 RefCountedThreadSafe() {}
22 protected:
23 ~RefCountedThreadSafe() {}
26 } // namespace base
28 // Ignore classes whose inheritance tree ends in WebKit's RefCounted base
29 // class. Though prone to error, this pattern is very prevalent in WebKit
30 // code, so do not issue any warnings.
31 namespace WebKit {
33 template <typename T>
34 class RefCounted {
35 public:
36 RefCounted() {}
37 ~RefCounted() {}
40 } // namespace WebKit
42 // Unsafe; should error.
43 class PublicRefCountedDtorInHeader
44 : public base::RefCounted<PublicRefCountedDtorInHeader> {
45 public:
46 PublicRefCountedDtorInHeader() {}
47 ~PublicRefCountedDtorInHeader() {}
49 private:
50 friend class base::RefCounted<PublicRefCountedDtorInHeader>;
53 // Unsafe; should error.
54 class PublicRefCountedThreadSafeDtorInHeader
55 : public base::RefCountedThreadSafe<
56 PublicRefCountedThreadSafeDtorInHeader> {
57 public:
58 PublicRefCountedThreadSafeDtorInHeader() {}
59 ~PublicRefCountedThreadSafeDtorInHeader() {}
61 private:
62 friend class base::RefCountedThreadSafe<
63 PublicRefCountedThreadSafeDtorInHeader>;
66 // Unsafe; should error.
67 class ProtectedRefCountedDtorInHeader
68 : public base::RefCounted<ProtectedRefCountedDtorInHeader> {
69 public:
70 ProtectedRefCountedDtorInHeader() {}
72 protected:
73 ~ProtectedRefCountedDtorInHeader() {}
75 private:
76 friend class base::RefCounted<ProtectedRefCountedDtorInHeader>;
79 // Safe; should not have errors
80 class ProtectedRefCountedVirtualDtorInHeader
81 : public base::RefCounted<ProtectedRefCountedVirtualDtorInHeader> {
82 public:
83 ProtectedRefCountedVirtualDtorInHeader() {}
85 protected:
86 virtual ~ProtectedRefCountedVirtualDtorInHeader() {}
88 private:
89 friend class base::RefCounted<ProtectedRefCountedVirtualDtorInHeader>;
93 // Safe; should not have errors.
94 class PrivateRefCountedDtorInHeader
95 : public base::RefCounted<PrivateRefCountedDtorInHeader> {
96 public:
97 PrivateRefCountedDtorInHeader() {}
99 private:
100 ~PrivateRefCountedDtorInHeader() {}
101 friend class base::RefCounted<PrivateRefCountedDtorInHeader>;
104 // Unsafe; A grandchild class ends up exposing their parent and grandparent's
105 // destructors.
106 class DerivedProtectedToPublicInHeader
107 : public ProtectedRefCountedVirtualDtorInHeader {
108 public:
109 DerivedProtectedToPublicInHeader() {}
110 ~DerivedProtectedToPublicInHeader() override {}
113 // Unsafe; A grandchild ends up implicitly exposing their parent and
114 // grantparent's destructors.
115 class ImplicitDerivedProtectedToPublicInHeader
116 : public ProtectedRefCountedVirtualDtorInHeader {
117 public:
118 ImplicitDerivedProtectedToPublicInHeader() {}
121 // Unsafe-but-ignored; should not have errors.
122 class WebKitPublicDtorInHeader
123 : public WebKit::RefCounted<WebKitPublicDtorInHeader> {
124 public:
125 WebKitPublicDtorInHeader() {}
126 ~WebKitPublicDtorInHeader() {}
129 // Unsafe-but-ignored; should not have errors.
130 class WebKitDerivedPublicDtorInHeader
131 : public WebKitPublicDtorInHeader {
132 public:
133 WebKitDerivedPublicDtorInHeader() {}
134 ~WebKitDerivedPublicDtorInHeader() {}
137 class APublicInterface {
138 public:
139 virtual ~APublicInterface() {}
140 virtual void DoFoo() = 0;
143 // Unsafe. "ImplementsAPublicInterface* foo" can be deleted via
144 // "delete (APublicInterface*)foo;".
145 class ImplementsAPublicInterface
146 : public APublicInterface,
147 public base::RefCounted<ImplementsAPublicInterface> {
148 public:
149 void DoFoo() override {}
151 protected:
152 ~ImplementsAPublicInterface() override {}
154 private:
155 friend class base::RefCounted<ImplementsAPublicInterface>;
158 class AnImplicitInterface {
159 public:
160 virtual void DoBar() {}
163 // Unsafe.
164 class ImplementsAnImplicitInterface
165 : public AnImplicitInterface,
166 public base::RefCounted<ImplementsAnImplicitInterface> {
167 public:
168 void DoBar() override {}
170 private:
171 friend class base::RefCounted<ImplementsAnImplicitInterface>;
172 ~ImplementsAnImplicitInterface() {}
175 // Safe. Private inheritance does not expose the base destructor.
176 class PrivatelyImplementsAPublicInterface
177 : private APublicInterface,
178 public base::RefCounted<PrivatelyImplementsAPublicInterface> {
179 public:
180 void DoFoo() override {}
182 private:
183 friend class base::RefCounted<PrivatelyImplementsAPublicInterface>;
184 ~PrivatelyImplementsAPublicInterface() override {}
187 // Unsafe.
188 class BaseInterface {
189 public:
190 virtual ~BaseInterface() {}
191 virtual void DoFoo() {}
193 class DerivedInterface : public BaseInterface {
194 protected:
195 ~DerivedInterface() override {}
197 class SomeOtherInterface {
198 public:
199 virtual ~SomeOtherInterface() {}
200 virtual void DoBar() {}
202 class RefcountedType : public base::RefCounted<RefcountedType> {
203 protected:
204 ~RefcountedType() {}
205 private:
206 friend class base::RefCounted<RefcountedType>;
208 class UnsafeInheritanceChain
209 : public DerivedInterface,
210 public SomeOtherInterface,
211 public RefcountedType {
212 public:
213 // DerivedInterface
214 void DoFoo() override {}
216 // SomeOtherInterface
217 void DoBar() override {}
219 protected:
220 ~UnsafeInheritanceChain() override {}
223 #endif // BASE_REFCOUNTED_H_