// Copyright 2024 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. // https://dev.chromium.org/developers/testing/no-compile-tests #include "base/containers/heap_array.h" #include namespace base { namespace { struct ConstructorRequiresArgs { ConstructorRequiresArgs(int val) : val_(val) {} int val_; }; struct NonTrivialClass { std::unique_ptr ptr_; }; void WontCompileUninithNonTrivialClass() { auto vec = HeapArray::Uninit(2u); // expected-error {{constraints not satisfied}} } void WontCompileWithSizeConstructorRequiresArgs() { auto vec = HeapArray::WithSize(2u); // expected-error {{constraints not satisfied}} } void WontCompileUninitConstructorRequiresArgs() { auto vec = base::HeapArray::Uninit(2u); // expected-error {{constraints not satisfied}} } void WontCompileConstNotAllowed() { auto vec = base::HeapArray(); // expected-error@*:* {{HeapArray cannot hold const types}} } void WontCompileReferencesNotAllowed() { auto vec = base::HeapArray(); // expected-error@*:* {{HeapArray cannot hold reference types}} } int* WontCompileDataLifetime() { return HeapArray::WithSize(1u).data(); // expected-error {{returning address}} } HeapArray::iterator WontCompileBeginLifetime() { return HeapArray::WithSize(1u).begin(); // expected-error {{returning address}} } HeapArray::iterator WontCompileEndLifetime() { return HeapArray::WithSize(1u).end(); // expected-error {{returning address}} } int& WontCompileIndexLifetime() { return HeapArray::WithSize(1u)[0]; // expected-error {{returning reference}} } base::span WontCompileSpanLifetime() { return HeapArray::WithSize(1u).as_span(); // expected-error {{returning address}} } } // namespace } // namespace base