1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// This is a "No Compile Test" suite.
// http://dev.chromium.org/developers/testing/no-compile-tests
#include <utility>
#include "base/functional/bind.h"
#include "third_party/blink/renderer/platform/heap/garbage_collected.h"
#include "third_party/blink/renderer/platform/wtf/functional.h"
namespace blink {
class UnretainableObject : public GarbageCollected<UnretainableObject> {};
class UnretainableMixin : public GarbageCollectedMixin {};
class UnretainableImpl : public GarbageCollected<UnretainableImpl>,
public GarbageCollectedMixin {};
// Helper macro to work around https://crbug.com/1482675. The compiler only
// emits diagnostic messages when it first creates a template instantiation, so
// subsequent uses of a template with the same arguments will not print the
// expected errors. This macro creates a type that shadows its corresponding
// type from an ancestor scope, but is distinct for the purposes of
// instantiating a template.
#define DECLARE_UNIQUE(type, name) \
class type : public ::blink::type {};\
type name
void GarbageCollectedCannotBeUnretained() {
{
DECLARE_UNIQUE(UnretainableObject, obj);
base::BindOnce([] (void*) {}, base::Unretained(&obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableObject, obj);
WTF::BindOnce([] (void*) {}, base::Unretained(&obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableObject, obj);
WTF::BindOnce([] (void*) {}, WTF::Unretained(&obj)); // expected-error@*:* {{WTF::Unretained() + GCed type is forbidden}}
}
}
void GCMixinCannotBeUnretained() {
{
DECLARE_UNIQUE(UnretainableMixin, obj);
base::BindOnce([] (void*) {}, base::Unretained(&obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableMixin, obj);
WTF::BindOnce([] (void*) {}, base::Unretained(&obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableMixin, obj);
WTF::BindOnce([] (void*) {}, WTF::Unretained(&obj)); // expected-error@*:* {{WTF::Unretained() + GCed type is forbidden}}
}
}
void GCImplWithMixinCannotBeUnretained() {
{
DECLARE_UNIQUE(UnretainableImpl, obj);
base::BindOnce([] (void*) {}, base::Unretained(&obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableImpl, obj);
WTF::BindOnce([] (void*) {}, base::Unretained(&obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableImpl, obj);
WTF::BindOnce([] (void*) {}, WTF::Unretained(&obj)); // expected-error@*:* {{WTF::Unretained() + GCed type is forbidden}}
}
}
void GarbageCollectedCannotBeBoundAsRawPointer(UnretainableObject* ptr) {
base::BindOnce([] (void* ptr) {}, ptr); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
WTF::BindOnce([] (UnretainableObject* ptr) {}, ptr); // expected-error@*:* {{Raw pointers are not allowed to bind into WTF::Function.}}
}
void GCMixinCannotBeBoundAsRawPointer(UnretainableMixin* ptr) {
base::BindOnce([] (void* ptr) {}, ptr); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
WTF::BindOnce([] (void* ptr) {}, ptr); // expected-error@*:* {{Raw pointers are not allowed to bind into WTF::Function.}}
}
void GCImplWithmixinCannotBeBoundAsRawPointer(UnretainableImpl* ptr) {
base::BindOnce([] (void* ptr) {}, ptr); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
WTF::BindOnce([] (UnretainableImpl* ptr) {}, ptr); // expected-error@*:* {{Raw pointers are not allowed to bind into WTF::Function.}}
}
void GarbageCollectedCannotBeBoundByCref() {
{
DECLARE_UNIQUE(UnretainableObject, obj);
base::BindOnce([] (const UnretainableObject& ref) {}, std::cref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableObject, obj);
WTF::BindOnce([] (const UnretainableObject& ref) {}, std::cref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
}
void GarbageCollectedCannotBeBoundByRef() {
{
DECLARE_UNIQUE(UnretainableObject, obj);
base::BindOnce([] (const UnretainableObject& ref) {}, std::ref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableObject, obj);
WTF::BindOnce([] (const UnretainableObject& ref) {}, std::ref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
}
void GCMixinCannotBeBoundByCref() {
{
DECLARE_UNIQUE(UnretainableMixin, obj);
base::BindOnce([] (const UnretainableMixin& ref) {}, std::cref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableMixin, obj);
WTF::BindOnce([] (const UnretainableMixin& ref) {}, std::cref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
}
void GCMixinCannotBeBoundByRef(UnretainableMixin& ref) {
{
DECLARE_UNIQUE(UnretainableMixin, obj);
base::BindOnce([] (const UnretainableMixin& ref) {}, std::ref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableMixin, obj);
WTF::BindOnce([] (const UnretainableMixin& ref) {}, std::ref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
}
void GCImplWithMixinCannotBeBoundByCref(UnretainableImpl& ref) {
{
DECLARE_UNIQUE(UnretainableImpl, obj);
base::BindOnce([] (const UnretainableImpl& ref) {}, std::cref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableImpl, obj);
WTF::BindOnce([] (const UnretainableImpl& ref) {}, std::cref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
}
void GCImplWithMixinCannotBeBoundByRef(UnretainableImpl& ref) {
{
DECLARE_UNIQUE(UnretainableImpl, obj);
base::BindOnce([] (const UnretainableImpl& ref) {}, std::ref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
{
DECLARE_UNIQUE(UnretainableImpl, obj);
WTF::BindOnce([] (const UnretainableImpl& ref) {}, std::ref(obj)); // expected-error@*:* {{Argument requires unretained storage, but type does not support `Unretained()`.}}
}
}
} // namespace blink
|