| 1 |
//===----------------------------------------------------------------------===// |
| 2 |
// |
| 3 |
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 |
// See https://llvm.org/LICENSE.txt for license information. |
| 5 |
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 6 |
// |
| 7 |
//===----------------------------------------------------------------------===// |
| 8 |
|
| 9 |
// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20 |
| 10 |
|
| 11 |
// <functional> |
| 12 |
|
| 13 |
// template<class F, class... Args> |
| 14 |
// constexpr unspecified bind_back(F&& f, Args&&... args); |
| 15 |
|
| 16 |
#include <functional> |
| 17 |
|
| 18 |
#include "types.h" |
| 19 |
|
| 20 |
constexpr int pass(int n) { return n; } |
| 21 |
|
| 22 |
void test() { |
| 23 |
{ // Test calling constexpr function from non-constexpr `bind_back` result |
| 24 |
auto f1 = std::bind_back(pass, 1); |
| 25 |
static_assert(f1() == 1); // expected-error {{static assertion expression is not an integral constant expression}} |
| 26 |
} |
| 27 |
|
| 28 |
{ // Test calling `bind_back` with template function |
| 29 |
auto f1 = std::bind_back(do_nothing, 2); |
| 30 |
// expected-error@-1 {{no matching function for call to 'bind_back'}} |
| 31 |
} |
| 32 |
|
| 33 |
{ // Mandates: is_constructible_v<decay_t<F>, F> |
| 34 |
struct F { |
| 35 |
F() = default; |
| 36 |
F(const F&) = default; |
| 37 |
F(F&) = delete; |
| 38 |
|
| 39 |
void operator()() {} |
| 40 |
}; |
| 41 |
|
| 42 |
F f; |
| 43 |
auto f1 = std::bind_back(f); |
| 44 |
// expected-error-re@*:* {{static assertion failed{{.*}}bind_back requires decay_t<F> to be constructible from F}} |
| 45 |
} |
| 46 |
|
| 47 |
{ // Mandates: is_move_constructible_v<decay_t<F>> |
| 48 |
struct F { |
| 49 |
F() = default; |
| 50 |
F(const F&) = default; |
| 51 |
F(F&&) = delete; |
| 52 |
|
| 53 |
void operator()() {} |
| 54 |
}; |
| 55 |
|
| 56 |
F f; |
| 57 |
auto f1 = std::bind_back(f); |
| 58 |
// expected-error-re@*:* {{static assertion failed{{.*}}bind_back requires decay_t<F> to be move constructible}} |
| 59 |
} |
| 60 |
|
| 61 |
{ // Mandates: (is_constructible_v<decay_t<Args>, Args> && ...) |
| 62 |
struct Arg { |
| 63 |
Arg() = default; |
| 64 |
Arg(const Arg&) = default; |
| 65 |
Arg(Arg&) = delete; |
| 66 |
}; |
| 67 |
|
| 68 |
Arg x; |
| 69 |
auto f = std::bind_back([](const Arg&) {}, x); |
| 70 |
// expected-error-re@*:* {{static assertion failed{{.*}}bind_back requires all decay_t<Args> to be constructible from respective Args}} |
| 71 |
// expected-error@*:* {{no matching constructor for initialization}} |
| 72 |
} |
| 73 |
|
| 74 |
{ // Mandates: (is_move_constructible_v<decay_t<Args>> && ...) |
| 75 |
struct Arg { |
| 76 |
Arg() = default; |
| 77 |
Arg(const Arg&) = default; |
| 78 |
Arg(Arg&&) = delete; |
| 79 |
}; |
| 80 |
|
| 81 |
Arg x; |
| 82 |
auto f = std::bind_back([](Arg&) {}, x); |
| 83 |
// expected-error-re@*:* {{static assertion failed{{.*}}bind_back requires all decay_t<Args> to be move constructible}} |
| 84 |
} |
| 85 |
} |