michael@0: // Copyright (c) 2012 The Chromium Authors. All rights reserved. michael@0: // Use of this source code is governed by a BSD-style license that can be michael@0: // found in the LICENSE file. michael@0: michael@0: #include "base_refcounted.h" michael@0: michael@0: #include michael@0: michael@0: namespace { michael@0: michael@0: // Unsafe; should error. michael@0: class AnonymousDerivedProtectedToPublicInImpl michael@0: : public ProtectedRefCountedDtorInHeader { michael@0: public: michael@0: AnonymousDerivedProtectedToPublicInImpl() {} michael@0: ~AnonymousDerivedProtectedToPublicInImpl() {} michael@0: }; michael@0: michael@0: } // namespace michael@0: michael@0: // Unsafe; should error. michael@0: class PublicRefCountedDtorInImpl michael@0: : public base::RefCounted { michael@0: public: michael@0: PublicRefCountedDtorInImpl() {} michael@0: ~PublicRefCountedDtorInImpl() {} michael@0: michael@0: private: michael@0: friend class base::RefCounted; michael@0: }; michael@0: michael@0: class Foo { michael@0: public: michael@0: class BarInterface { michael@0: protected: michael@0: virtual ~BarInterface() {} michael@0: }; michael@0: michael@0: typedef base::RefCounted RefCountedBar; michael@0: typedef RefCountedBar AnotherTypedef; michael@0: }; michael@0: michael@0: class Baz { michael@0: public: michael@0: typedef typename Foo::AnotherTypedef MyLocalTypedef; michael@0: }; michael@0: michael@0: // Unsafe; should error. michael@0: class UnsafeTypedefChainInImpl : public Baz::MyLocalTypedef { michael@0: public: michael@0: UnsafeTypedefChainInImpl() {} michael@0: ~UnsafeTypedefChainInImpl() {} michael@0: }; michael@0: michael@0: int main() { michael@0: PublicRefCountedDtorInHeader bad; michael@0: PublicRefCountedDtorInImpl also_bad; michael@0: michael@0: ProtectedRefCountedDtorInHeader* protected_ok = NULL; michael@0: PrivateRefCountedDtorInHeader* private_ok = NULL; michael@0: michael@0: DerivedProtectedToPublicInHeader still_bad; michael@0: PublicRefCountedThreadSafeDtorInHeader another_bad_variation; michael@0: AnonymousDerivedProtectedToPublicInImpl and_this_is_bad_too; michael@0: ImplicitDerivedProtectedToPublicInHeader bad_yet_again; michael@0: UnsafeTypedefChainInImpl and_again_this_is_bad; michael@0: michael@0: WebKitPublicDtorInHeader ignored; michael@0: WebKitDerivedPublicDtorInHeader still_ignored; michael@0: michael@0: return 0; michael@0: }