xref: /aosp_15_r20/external/cronet/base/containers/to_vector_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// http://dev.chromium.org/developers/testing/no-compile-tests
7
8#include "base/containers/to_vector.h"
9
10#include <tuple>
11#include <utility>
12#include <vector>
13
14namespace base {
15
16// ToVector() doesn't implicitly deduce initializer lists.
17void InitializerList() {
18  std::ignore = ToVector({"aaa", "bbb", "ccc"}); // expected-error@*:* {{no matching function for call to 'ToVector'}}
19}
20
21// Lambdas operating on rvalue ranges of move-only elements expect lvalue
22// references to the element type.
23void MoveOnlyProjections() {
24  struct MoveOnly {
25    MoveOnly() = default;
26
27    MoveOnly(const MoveOnly&) = delete;
28    MoveOnly& operator=(const MoveOnly&) = delete;
29
30    MoveOnly(MoveOnly&&) = default;
31    MoveOnly& operator=(MoveOnly&&) = default;
32  };
33
34  std::vector<MoveOnly> vec;
35  std::ignore = ToVector(std::move(vec), [](MoveOnly arg) {
36    return arg;
37  }); // expected-error@*:* {{no matching function for call to 'ToVector'}}
38  std::ignore = ToVector(std::move(vec), [](MoveOnly&& arg) {
39    return std::move(arg);
40  }); // expected-error@*:* {{no matching function for call to 'ToVector'}}
41}
42
43}  // namespace base
44