xref: /aosp_15_r20/external/cronet/base/containers/heap_array_nocompile.nc (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// This is a "No Compile Test" suite.
6// https://dev.chromium.org/developers/testing/no-compile-tests
7
8#include "base/containers/heap_array.h"
9
10#include <memory>
11
12namespace base {
13namespace {
14
15struct ConstructorRequiresArgs {
16  ConstructorRequiresArgs(int val) : val_(val) {}
17  int val_;
18};
19
20struct NonTrivialClass {
21  std::unique_ptr<int> ptr_;
22};
23
24void WontCompileUninithNonTrivialClass() {
25  auto vec = HeapArray<NonTrivialClass>::Uninit(2u);  // expected-error {{constraints not satisfied}}
26}
27
28void WontCompileWithSizeConstructorRequiresArgs() {
29  auto vec = HeapArray<ConstructorRequiresArgs>::WithSize(2u);  // expected-error {{constraints not satisfied}}
30}
31
32void WontCompileUninitConstructorRequiresArgs() {
33  auto vec = base::HeapArray<ConstructorRequiresArgs>::Uninit(2u);  // expected-error {{constraints not satisfied}}
34}
35
36void WontCompileConstNotAllowed() {
37  auto vec = base::HeapArray<const int>();  // expected-error@*:* {{HeapArray cannot hold const types}}
38}
39
40void WontCompileReferencesNotAllowed() {
41  auto vec = base::HeapArray<int&>();  // expected-error@*:* {{HeapArray cannot hold reference types}}
42}
43
44int* WontCompileDataLifetime() {
45  return HeapArray<int>::WithSize(1u).data();  // expected-error {{returning address}}
46}
47
48HeapArray<int>::iterator WontCompileBeginLifetime() {
49  return HeapArray<int>::WithSize(1u).begin();  // expected-error {{returning address}}
50}
51
52HeapArray<int>::iterator WontCompileEndLifetime() {
53  return HeapArray<int>::WithSize(1u).end();  // expected-error {{returning address}}
54}
55
56int& WontCompileIndexLifetime() {
57  return HeapArray<int>::WithSize(1u)[0];  // expected-error {{returning reference}}
58}
59
60base::span<int> WontCompileSpanLifetime() {
61  return HeapArray<int>::WithSize(1u).as_span(); // expected-error {{returning address}}
62}
63
64}  // namespace
65}  // namespace base
66