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

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

Issue 10005022: Check for public dtors on base::RefCounted types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Now with moar flags Created 8 years, 8 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
(Empty)
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.
4
5 #ifndef BASE_REFCOUNTED_H_
6 #define BASE_REFCOUNTED_H_
7
8 namespace base {
9
10 // Define a 'dummy' set of refcounting templates
Nico 2012/04/13 22:40:55 useless comment, remove
11 template <typename T>
12 class RefCounted {
13 public:
14 RefCounted() {}
15 ~RefCounted() {}
16 };
17
18 template <typename T>
19 class RefCountedThreadSafe {
20 public:
21 RefCountedThreadSafe() {}
22 ~RefCountedThreadSafe() {}
23 };
24
25 } // namespace base
26
27 // However, WebKit ref-counted classes should be ignored.
Nico 2012/04/13 22:40:55 You might want to explain somewhere why (say, in t
28 namespace WebKit {
29
30 template <typename T>
31 class RefCounted {
32 public:
33 RefCounted() {}
34 ~RefCounted() {}
35 };
36
37 } // namespace WebKit
38
39 // Unsafe; should error.
40 class PublicRefCountedDtorInHeader
41 : public base::RefCounted<PublicRefCountedDtorInHeader> {
42 public:
43 PublicRefCountedDtorInHeader() {}
44 ~PublicRefCountedDtorInHeader() {}
45
46 private:
47 friend class base::RefCounted<PublicRefCountedDtorInHeader>;
48 };
49
50 // Unsafe; should error.
51 class PublicRefCountedThreadSafeDtorInHeader
52 : public base::RefCountedThreadSafe<
53 PublicRefCountedThreadSafeDtorInHeader> {
54 public:
55 PublicRefCountedThreadSafeDtorInHeader() {}
56 ~PublicRefCountedThreadSafeDtorInHeader() {}
57
58 private:
59 friend class base::RefCountedThreadSafe<
60 PublicRefCountedThreadSafeDtorInHeader>;
61 };
62
63 // Safe; should not have errors.
64 class ProtectedRefCountedDtorInHeader
65 : public base::RefCounted<ProtectedRefCountedDtorInHeader> {
66 public:
67 ProtectedRefCountedDtorInHeader() {}
68
69 protected:
70 ~ProtectedRefCountedDtorInHeader() {}
71
72 private:
73 friend class base::RefCounted<ProtectedRefCountedDtorInHeader>;
74 };
75
76 // Safe; should not have errors.
77 class PrivateRefCountedDtorInHeader
78 : public base::RefCounted<PrivateRefCountedDtorInHeader> {
79 public:
80 PrivateRefCountedDtorInHeader() {}
81
82 private:
83 ~PrivateRefCountedDtorInHeader() {}
84 friend class base::RefCounted<PrivateRefCountedDtorInHeader>;
85 };
86
87 // Unsafe; A grandchild class ends up exposing their parent and grandparent's
88 // destructors.
89 class DerivedProtectedToPublicInHeader
90 : public ProtectedRefCountedDtorInHeader {
91 public:
92 DerivedProtectedToPublicInHeader() {}
93 ~DerivedProtectedToPublicInHeader() {}
94 };
95
96 // Unsafe; A grandchild ends up implicitly exposing their parent and
97 // grantparent's destructors.
98 class ImplicitDerivedProtectedToPublicInHeader
99 : public ProtectedRefCountedDtorInHeader {
100 public:
101 ImplicitDerivedProtectedToPublicInHeader() {}
102 };
103
104 // Unsafe-but-ignored; should not have errors.
105 class WebKitPublicDtorInHeader
106 : public WebKit::RefCounted<WebKitPublicDtorInHeader> {
107 public:
108 WebKitPublicDtorInHeader() {}
109 ~WebKitPublicDtorInHeader() {}
110 };
111
112 // Unsafe-but-ignored; should not have errors.
113 class WebKitDerivedPublicDtorInHeader
114 : public WebKitPublicDtorInHeader {
115 public:
116 WebKitDerivedPublicDtorInHeader() {}
117 ~WebKitDerivedPublicDtorInHeader() {}
118 };
119
120 #endif // BASE_REFCOUNTED_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698