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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/clang/plugins/FindBadConstructs.cpp ('k') | tools/clang/plugins/tests/base_refcounted.flags » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/plugins/tests/base_refcounted.h
diff --git a/tools/clang/plugins/tests/base_refcounted.h b/tools/clang/plugins/tests/base_refcounted.h
index 1e532159972c56e65160f20e9a0bb353a06d2838..840009da3f426c7f910dd5b6980be156994d76bd 100644
--- a/tools/clang/plugins/tests/base_refcounted.h
+++ b/tools/clang/plugins/tests/base_refcounted.h
@@ -11,6 +11,7 @@ template <typename T>
class RefCounted {
public:
RefCounted() {}
+ protected:
~RefCounted() {}
};
@@ -18,6 +19,7 @@ template <typename T>
class RefCountedThreadSafe {
public:
RefCountedThreadSafe() {}
+ protected:
~RefCountedThreadSafe() {}
};
@@ -118,4 +120,90 @@ class WebKitDerivedPublicDtorInHeader
~WebKitDerivedPublicDtorInHeader() {}
};
+class APublicInterface {
+ public:
+ virtual ~APublicInterface() {}
+ virtual void DoFoo() = 0;
+};
+
+// Unsafe. "ImplementsAPublicInterface* foo" can be deleted via
+// "delete (APublicInterface*)foo;".
+class ImplementsAPublicInterface
+ : public APublicInterface,
+ public base::RefCounted<ImplementsAPublicInterface> {
+ public:
+ virtual void DoFoo() override {}
+
+ protected:
+ virtual ~ImplementsAPublicInterface() {}
+
+ private:
+ friend class base::RefCounted<ImplementsAPublicInterface>;
+};
+
+class AnImplicitInterface {
+ public:
+ virtual void DoBar() {}
+};
+
+// Unsafe.
+class ImplementsAnImplicitInterface
+ : public AnImplicitInterface,
+ public base::RefCounted<ImplementsAnImplicitInterface> {
+ public:
+ virtual void DoBar() override {}
+
+ private:
+ friend class base::RefCounted<ImplementsAnImplicitInterface>;
+ ~ImplementsAnImplicitInterface() {}
+};
+
+// Safe. Private inheritance does not expose the base destructor.
+class PrivatelyImplementsAPublicInterface
+ : private APublicInterface,
+ public base::RefCounted<PrivatelyImplementsAPublicInterface> {
+ public:
+ virtual void DoFoo() override {}
+
+ private:
+ friend class base::RefCounted<PrivatelyImplementsAPublicInterface>;
+ virtual ~PrivatelyImplementsAPublicInterface() {}
+};
+
+// Unsafe.
+class BaseInterface {
+ public:
+ virtual ~BaseInterface() {}
+ virtual void DoFoo() {}
+};
+class DerivedInterface : public BaseInterface {
+ protected:
+ virtual ~DerivedInterface() {}
+};
+class SomeOtherInterface {
+ public:
+ virtual ~SomeOtherInterface() {}
+ virtual void DoBar() {}
+};
+class RefcountedType : public base::RefCounted<RefcountedType> {
+ protected:
+ ~RefcountedType() {}
+ private:
+ friend class base::RefCounted<RefcountedType>;
+};
+class UnsafeInheritanceChain
+ : public DerivedInterface,
+ public SomeOtherInterface,
+ public RefcountedType {
+ public:
+ // DerivedInterface
+ virtual void DoFoo() override {}
+
+ // SomeOtherInterface
+ virtual void DoBar() override {}
+
+ protected:
+ virtual ~UnsafeInheritanceChain() {}
+};
+
#endif // BASE_REFCOUNTED_H_
« 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