1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/tools/clang/plugins/tests/base_refcounted.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +// Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#include "base_refcounted.h" 1.9 + 1.10 +#include <cstddef> 1.11 + 1.12 +namespace { 1.13 + 1.14 +// Unsafe; should error. 1.15 +class AnonymousDerivedProtectedToPublicInImpl 1.16 + : public ProtectedRefCountedDtorInHeader { 1.17 + public: 1.18 + AnonymousDerivedProtectedToPublicInImpl() {} 1.19 + ~AnonymousDerivedProtectedToPublicInImpl() {} 1.20 +}; 1.21 + 1.22 +} // namespace 1.23 + 1.24 +// Unsafe; should error. 1.25 +class PublicRefCountedDtorInImpl 1.26 + : public base::RefCounted<PublicRefCountedDtorInImpl> { 1.27 + public: 1.28 + PublicRefCountedDtorInImpl() {} 1.29 + ~PublicRefCountedDtorInImpl() {} 1.30 + 1.31 + private: 1.32 + friend class base::RefCounted<PublicRefCountedDtorInImpl>; 1.33 +}; 1.34 + 1.35 +class Foo { 1.36 + public: 1.37 + class BarInterface { 1.38 + protected: 1.39 + virtual ~BarInterface() {} 1.40 + }; 1.41 + 1.42 + typedef base::RefCounted<BarInterface> RefCountedBar; 1.43 + typedef RefCountedBar AnotherTypedef; 1.44 +}; 1.45 + 1.46 +class Baz { 1.47 + public: 1.48 + typedef typename Foo::AnotherTypedef MyLocalTypedef; 1.49 +}; 1.50 + 1.51 +// Unsafe; should error. 1.52 +class UnsafeTypedefChainInImpl : public Baz::MyLocalTypedef { 1.53 + public: 1.54 + UnsafeTypedefChainInImpl() {} 1.55 + ~UnsafeTypedefChainInImpl() {} 1.56 +}; 1.57 + 1.58 +int main() { 1.59 + PublicRefCountedDtorInHeader bad; 1.60 + PublicRefCountedDtorInImpl also_bad; 1.61 + 1.62 + ProtectedRefCountedDtorInHeader* protected_ok = NULL; 1.63 + PrivateRefCountedDtorInHeader* private_ok = NULL; 1.64 + 1.65 + DerivedProtectedToPublicInHeader still_bad; 1.66 + PublicRefCountedThreadSafeDtorInHeader another_bad_variation; 1.67 + AnonymousDerivedProtectedToPublicInImpl and_this_is_bad_too; 1.68 + ImplicitDerivedProtectedToPublicInHeader bad_yet_again; 1.69 + UnsafeTypedefChainInImpl and_again_this_is_bad; 1.70 + 1.71 + WebKitPublicDtorInHeader ignored; 1.72 + WebKitDerivedPublicDtorInHeader still_ignored; 1.73 + 1.74 + return 0; 1.75 +}