brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.7 KiB · 6a63b65 Raw
88 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 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 20constexpr int pass(int n) { return n; }21 22void test() {23  { // Test calling constexpr function from non-constexpr `bind_back` result24    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 function29    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    // expected-error@*:* 0-1{{call to deleted constructor of 'F'}}73    // expected-error@*:* 0-1{{call to deleted constructor of 'Arg'}}74  }75 76  { // Mandates: (is_move_constructible_v<decay_t<Args>> && ...)77    struct Arg {78      Arg()           = default;79      Arg(const Arg&) = default;80      Arg(Arg&&)      = delete;81    };82 83    Arg x;84    auto f = std::bind_back([](Arg&) {}, x);85    // expected-error-re@*:* {{static assertion failed{{.*}}bind_back requires all decay_t<Args> to be move constructible}}86  }87}88