• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "base_refcounted.h"
6 
7 #include <cstddef>
8 
9 namespace {
10 
11 // Unsafe; should error.
12 class AnonymousDerivedProtectedToPublicInImpl
13     : public ProtectedRefCountedVirtualDtorInHeader {
14  public:
AnonymousDerivedProtectedToPublicInImpl()15   AnonymousDerivedProtectedToPublicInImpl() {}
~AnonymousDerivedProtectedToPublicInImpl()16   virtual ~AnonymousDerivedProtectedToPublicInImpl() {}
17 };
18 
19 // Unsafe; but we should only warn on the base class.
20 class AnonymousDerivedProtectedOnDerived
21     : public ProtectedRefCountedDtorInHeader {
22  protected:
~AnonymousDerivedProtectedOnDerived()23   ~AnonymousDerivedProtectedOnDerived() {}
24 };
25 
26 }  // namespace
27 
28 // Unsafe; should error.
29 class PublicRefCountedDtorInImpl
30     : public base::RefCounted<PublicRefCountedDtorInImpl> {
31  public:
PublicRefCountedDtorInImpl()32   PublicRefCountedDtorInImpl() {}
~PublicRefCountedDtorInImpl()33   ~PublicRefCountedDtorInImpl() {}
34 
35  private:
36   friend class base::RefCounted<PublicRefCountedDtorInImpl>;
37 };
38 
39 class Foo {
40  public:
41   class BarInterface {
42    protected:
~BarInterface()43     virtual ~BarInterface() {}
44   };
45 
46   typedef base::RefCounted<BarInterface> RefCountedBar;
47   typedef RefCountedBar AnotherTypedef;
48 };
49 
50 class Baz {
51  public:
52   typedef typename Foo::AnotherTypedef MyLocalTypedef;
53 };
54 
55 // Unsafe; should error.
56 class UnsafeTypedefChainInImpl : public Baz::MyLocalTypedef {
57  public:
UnsafeTypedefChainInImpl()58   UnsafeTypedefChainInImpl() {}
~UnsafeTypedefChainInImpl()59   ~UnsafeTypedefChainInImpl() {}
60 };
61 
main()62 int main() {
63   PublicRefCountedDtorInHeader bad;
64   PublicRefCountedDtorInImpl also_bad;
65 
66   ProtectedRefCountedDtorInHeader* even_badder = NULL;
67   PrivateRefCountedDtorInHeader* private_ok = NULL;
68 
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;
74 
75   WebKitPublicDtorInHeader ignored;
76   WebKitDerivedPublicDtorInHeader still_ignored;
77 
78   return 0;
79 }
80