[MD settings] moving attached() code
[chromium-blink-merge.git] / tools / clang / plugins / tests / base_refcounted.cpp
blob46e8975c597c46558be8728c094bf68d8db310fa
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 #include "base_refcounted.h"
7 #include <cstddef>
9 namespace {
11 // Unsafe; should error.
12 class AnonymousDerivedProtectedToPublicInImpl
13 : public ProtectedRefCountedVirtualDtorInHeader {
14 public:
15 AnonymousDerivedProtectedToPublicInImpl() {}
16 ~AnonymousDerivedProtectedToPublicInImpl() override {}
19 // Unsafe; but we should only warn on the base class.
20 class AnonymousDerivedProtectedOnDerived
21 : public ProtectedRefCountedDtorInHeader {
22 protected:
23 ~AnonymousDerivedProtectedOnDerived() {}
26 } // namespace
28 // Unsafe; should error.
29 class PublicRefCountedDtorInImpl
30 : public base::RefCounted<PublicRefCountedDtorInImpl> {
31 public:
32 PublicRefCountedDtorInImpl() {}
33 ~PublicRefCountedDtorInImpl() {}
35 private:
36 friend class base::RefCounted<PublicRefCountedDtorInImpl>;
39 class Foo {
40 public:
41 class BarInterface {
42 protected:
43 virtual ~BarInterface() {}
46 typedef base::RefCounted<BarInterface> RefCountedBar;
47 typedef RefCountedBar AnotherTypedef;
50 class Baz {
51 public:
52 typedef typename Foo::AnotherTypedef MyLocalTypedef;
55 // Unsafe; should error.
56 class UnsafeTypedefChainInImpl : public Baz::MyLocalTypedef {
57 public:
58 UnsafeTypedefChainInImpl() {}
59 ~UnsafeTypedefChainInImpl() {}
62 int main() {
63 PublicRefCountedDtorInHeader bad;
64 PublicRefCountedDtorInImpl also_bad;
66 ProtectedRefCountedDtorInHeader* even_badder = NULL;
67 PrivateRefCountedDtorInHeader* private_ok = NULL;
69 DerivedProtectedToPublicInHeader still_bad;
70 PublicRefCountedThreadSafeDtorInHeader another_bad_variation;
71 AnonymousDerivedProtectedToPublicInImpl and_this_is_bad_too;
72 ImplicitDerivedProtectedToPublicInHeader bad_yet_again;
73 UnsafeTypedefChainInImpl and_again_this_is_bad;
75 WebKitPublicDtorInHeader ignored;
76 WebKitDerivedPublicDtorInHeader still_ignored;
78 return 0;