// Copyright 2017 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "base/memory/ref_counted.h" #include "base/memory/ref_counted_delete_on_sequence.h" namespace base { class InitialRefCountIsZero : public base::RefCounted { public: InitialRefCountIsZero() {} private: friend class base::RefCounted; ~InitialRefCountIsZero() {} }; #if defined(NCTEST_ADOPT_REF_TO_ZERO_START) // [r"fatal error: static assertion failed due to requirement 'std::is_same::value': Use AdoptRef only if the reference count starts from one\."] void WontCompile() { AdoptRef(new InitialRefCountIsZero()); } #endif #if defined(NCTEST_WRONG_REFCOUNT_BASE_CLASS) // [r"fatal error: static assertion failed due to requirement 'std::is_base_of_v': T implements RefCounted, but U is not a base of T\."] class Foo : public base::RefCounted { private: friend class base::RefCounted; ~Foo() {} }; class Bar : public base::RefCounted { private: friend class base::RefCounted; ~Bar() {} }; void WontCompile() { scoped_refptr ptr; } #endif #if defined(NCTEST_WRONG_REFCOUNT_THREADSAFE_BASE_CLASS) // [r"fatal error: static assertion failed due to requirement 'std::is_base_of_v': T implements RefCountedThreadSafe, but U is not a base of T\."] class Foo : public base::RefCountedThreadSafe { private: friend class base::RefCountedThreadSafe; ~Foo() {} }; class Bar : public base::RefCountedThreadSafe { private: friend class base::RefCountedThreadSafe; ~Bar() {} }; void WontCompile() { scoped_refptr ptr; } #endif #if defined(NCTEST_WRONG_REFCOUNT_ON_SEQUENCE_BASE_CLASS) // [r"fatal error: static assertion failed due to requirement 'std::is_base_of_v': T implements RefCountedDeleteOnSequence, but U is not a base of T\."] class Foo : public base::RefCountedDeleteOnSequence { private: friend class base::RefCountedDeleteOnSequence; friend class base::DeleteHelper; ~Foo() {} }; class Bar : public base::RefCountedDeleteOnSequence { private: friend class base::RefCountedDeleteOnSequence; friend class base::DeleteHelper; ~Bar() {} }; void WontCompile() { scoped_refptr ptr; } #endif #if defined(NCTEST_SUBCLASS_OVERRIDES_REFCOUNT_PREFERENCE) // [r"fatal error: static assertion failed due to requirement .*: It's unsafe to override the ref count preference\. Please remove REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE from subclasses\."] class Base : public base::RefCounted { protected: friend class base::RefCounted; ~Base() {} }; class Derived : public Base { public: REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE(); }; void WontCompile() { scoped_refptr ptr; } #endif #if defined(NCTEST_SUBCLASS_OVERRIDES_REFCOUNT_PREFERENCE_THREADSAFE) // [r"fatal error: static assertion failed due to requirement .*: It's unsafe to override the ref count preference\. Please remove REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE from subclasses\."] class Base : public base::RefCountedThreadSafe { protected: friend class base::RefCountedThreadSafe; ~Base() {} }; class Derived : public Base { public: REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE(); }; void WontCompile() { scoped_refptr ptr; } #endif #if defined(NCTEST_SUBCLASS_OVERRIDES_REFCOUNT_PREFERENCE_SEQUENCE) // [r"fatal error: static assertion failed due to requirement .*: It's unsafe to override the ref count preference\. Please remove REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE from subclasses\."] class Base : public base::RefCountedDeleteOnSequence { protected: friend class base::RefCountedDeleteOnSequence; friend class base::DeleteHelper; ~Base() {} }; class Derived : public Base { public: REQUIRE_ADOPTION_FOR_REFCOUNTED_TYPE(); }; void WontCompile() { scoped_refptr ptr; } #endif } // namespace base