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
9namespace {
10
11// Unsafe; should error.
12class AnonymousDerivedProtectedToPublicInImpl
13    : public ProtectedRefCountedVirtualDtorInHeader {
14 public:
15  AnonymousDerivedProtectedToPublicInImpl() {}
16  virtual ~AnonymousDerivedProtectedToPublicInImpl() {}
17};
18
19// Unsafe; but we should only warn on the base class.
20class AnonymousDerivedProtectedOnDerived
21    : public ProtectedRefCountedDtorInHeader {
22 protected:
23  ~AnonymousDerivedProtectedOnDerived() {}
24};
25
26}  // namespace
27
28// Unsafe; should error.
29class PublicRefCountedDtorInImpl
30    : public base::RefCounted<PublicRefCountedDtorInImpl> {
31 public:
32  PublicRefCountedDtorInImpl() {}
33  ~PublicRefCountedDtorInImpl() {}
34
35 private:
36  friend class base::RefCounted<PublicRefCountedDtorInImpl>;
37};
38
39class Foo {
40 public:
41  class BarInterface {
42   protected:
43    virtual ~BarInterface() {}
44  };
45
46  typedef base::RefCounted<BarInterface> RefCountedBar;
47  typedef RefCountedBar AnotherTypedef;
48};
49
50class Baz {
51 public:
52  typedef typename Foo::AnotherTypedef MyLocalTypedef;
53};
54
55// Unsafe; should error.
56class UnsafeTypedefChainInImpl : public Baz::MyLocalTypedef {
57 public:
58  UnsafeTypedefChainInImpl() {}
59  ~UnsafeTypedefChainInImpl() {}
60};
61
62int 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