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_value_list.h" 9 10#include <tuple> 11#include <utility> 12#include <vector> 13 14namespace base { 15 16// ToValueList() doesn't implicitly deduce initializer lists. 17void InitializerList() { 18 std::ignore = ToValueList({"aaa", "bbb", "ccc"}); // expected-error@*:* {{no matching function for call to 'ToValueList'}} 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 = ToValueList(std::move(vec), [](MoveOnly arg) { 36 return arg; 37 }); // expected-error@*:* {{no matching function for call to 'ToValueList'}} 38 std::ignore = ToValueList(std::move(vec), [](MoveOnly&& arg) { 39 return std::move(arg); 40 }); // expected-error@*:* {{no matching function for call to 'ToValueList'}} 41} 42 43// Return type of the projection must be compatible with Value::List::Append(). 44void AppendableToList() { 45 std::vector<int> vec; 46 std::ignore = ToValueList(vec, [](int) -> int* { return nullptr; }); // expected-error@*:* {{no matching function for call to 'ToValueList'}} 47} 48 49} // namespace base 50