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

Unified Diff: tools/clang/plugins/tests/base_refcounted.cpp

Issue 10005022: Check for public dtors on base::RefCounted types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Copyright update 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/clang/plugins/tests/base_refcounted.h ('k') | tools/clang/plugins/tests/base_refcounted.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/plugins/tests/base_refcounted.cpp
diff --git a/tools/clang/plugins/tests/base_refcounted.cpp b/tools/clang/plugins/tests/base_refcounted.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..364a3e888cf09bf37a3360599ce3b8fc51a34770
--- /dev/null
+++ b/tools/clang/plugins/tests/base_refcounted.cpp
@@ -0,0 +1,72 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base_refcounted.h"
+
+#include <cstddef>
+
+namespace {
+
+// Unsafe; should error.
+class AnonymousDerivedProtectedToPublicInImpl
+ : public ProtectedRefCountedDtorInHeader {
+ public:
+ AnonymousDerivedProtectedToPublicInImpl() {}
+ ~AnonymousDerivedProtectedToPublicInImpl() {}
+};
+
+} // namespace
+
+// Unsafe; should error.
+class PublicRefCountedDtorInImpl
+ : public base::RefCounted<PublicRefCountedDtorInImpl> {
+ public:
+ PublicRefCountedDtorInImpl() {}
+ ~PublicRefCountedDtorInImpl() {}
+
+ private:
+ friend class base::RefCounted<PublicRefCountedDtorInImpl>;
+};
+
+class Foo {
+ public:
+ class BarInterface {
+ protected:
+ virtual ~BarInterface() {}
+ };
+
+ typedef base::RefCounted<BarInterface> RefCountedBar;
+ typedef RefCountedBar AnotherTypedef;
+};
+
+class Baz {
+ public:
+ typedef typename Foo::AnotherTypedef MyLocalTypedef;
+};
+
+// Unsafe; should error.
+class UnsafeTypedefChainInImpl : public Baz::MyLocalTypedef {
+ public:
+ UnsafeTypedefChainInImpl() {}
+ ~UnsafeTypedefChainInImpl() {}
+};
+
+int main() {
+ PublicRefCountedDtorInHeader bad;
+ PublicRefCountedDtorInImpl also_bad;
+
+ ProtectedRefCountedDtorInHeader* protected_ok = NULL;
+ PrivateRefCountedDtorInHeader* private_ok = NULL;
+
+ DerivedProtectedToPublicInHeader still_bad;
+ PublicRefCountedThreadSafeDtorInHeader another_bad_variation;
+ AnonymousDerivedProtectedToPublicInImpl and_this_is_bad_too;
+ ImplicitDerivedProtectedToPublicInHeader bad_yet_again;
+ UnsafeTypedefChainInImpl and_again_this_is_bad;
+
+ WebKitPublicDtorInHeader ignored;
+ WebKitDerivedPublicDtorInHeader still_ignored;
+
+ return 0;
+}
« no previous file with comments | « tools/clang/plugins/tests/base_refcounted.h ('k') | tools/clang/plugins/tests/base_refcounted.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698