| 1 | // Copyright (C) 2010-2025 Free Software Foundation, Inc. |
| 2 | // |
| 3 | // This file is part of the GNU ISO C++ Library. This library is free |
| 4 | // software; you can redistribute it and/or modify it under the |
| 5 | // terms of the GNU General Public License as published by the |
| 6 | // Free Software Foundation; either version 3, or (at your option) |
| 7 | // any later version. |
| 8 | |
| 9 | // This library is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | |
| 14 | // You should have received a copy of the GNU General Public License along |
| 15 | // with this library; see the file COPYING3. If not see |
| 16 | // <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | // 20.7.11 Function template bind |
| 19 | |
| 20 | // { dg-options "-Wdeprecated-declarations" } |
| 21 | // { dg-do run { target c++11 } } |
| 22 | |
| 23 | #include <functional> |
| 24 | #include <testsuite_hooks.h> |
| 25 | |
| 26 | // target must be invoked with cv-quals of call wrapper |
| 27 | |
| 28 | struct X |
| 29 | { |
| 30 | int operator()() { return 0; } |
| 31 | int operator()() const { return 1; } |
| 32 | int operator()() volatile { return 2; } |
| 33 | int operator()() const volatile { return 3; } |
| 34 | |
| 35 | int operator()(int, int, int) { return 0; } |
| 36 | int operator()(int, int, int) const { return 1; } |
| 37 | int operator()(int, int, int) volatile { return 2; } |
| 38 | int operator()(int, int, int) const volatile { return 3; } |
| 39 | }; |
| 40 | |
| 41 | using std::placeholders::_1; |
| 42 | using std::placeholders::_2; |
| 43 | |
| 44 | void test01() |
| 45 | { |
| 46 | auto b0 = std::bind(X()); |
| 47 | VERIFY( b0() == 0 ); |
| 48 | |
| 49 | const auto b1 = std::bind(X()); |
| 50 | VERIFY( b1() == 1 ); |
| 51 | |
| 52 | #if __cplusplus <= 201703L |
| 53 | volatile auto b2 = std::bind(X()); |
| 54 | VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } |
| 55 | |
| 56 | const volatile auto b3 = std::bind(X()); |
| 57 | VERIFY( b3() == 3 ); // { dg-warning "deprecated" "" { target c++17_only } } |
| 58 | #endif |
| 59 | } |
| 60 | |
| 61 | void test02() |
| 62 | { |
| 63 | auto b0 = std::bind<int>(X()); |
| 64 | VERIFY( b0() == 0 ); |
| 65 | |
| 66 | const auto b1 = std::bind<int>(X()); |
| 67 | VERIFY( b1() == 1 ); |
| 68 | |
| 69 | #if __cplusplus <= 201703L |
| 70 | volatile auto b2 = std::bind<int>(X()); |
| 71 | VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } |
| 72 | |
| 73 | const volatile auto b3 = std::bind<int>(X()); |
| 74 | VERIFY( b3() == 3 ); // { dg-warning "deprecated" "" { target c++17_only } } |
| 75 | #endif |
| 76 | } |
| 77 | |
| 78 | void test03() |
| 79 | { |
| 80 | auto b0 = std::bind(X(), 0, _1, _2); |
| 81 | VERIFY( b0(0, 0) == 0 ); |
| 82 | |
| 83 | const auto b1 = std::bind(X(), _1, 0, _2); |
| 84 | VERIFY( b1(0, 0) == 1 ); |
| 85 | |
| 86 | #if __cplusplus <= 201703L |
| 87 | volatile auto b2 = std::bind(X(), _1, _2, 0); |
| 88 | VERIFY( b2(0, 0) == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } |
| 89 | |
| 90 | const volatile auto b3 = std::bind(X(), _1, 0, _2); |
| 91 | VERIFY( b3(0, 0) == 3 ); // { dg-warning "deprecated" "" { target c++17_only } } |
| 92 | #endif |
| 93 | } |
| 94 | |
| 95 | void test04() |
| 96 | { |
| 97 | auto b0 = std::bind<int>(X(), 0, _1, _2); |
| 98 | VERIFY( b0(0, 0) == 0 ); |
| 99 | |
| 100 | const auto b1 = std::bind<int>(X(), _1, 0, _2); |
| 101 | VERIFY( b1(0, 0) == 1 ); |
| 102 | |
| 103 | #if __cplusplus <= 201703L |
| 104 | volatile auto b2 = std::bind<int>(X(), _1, _2, 0); |
| 105 | VERIFY( b2(0, 0) == 2 ); // { dg-warning "deprecated" "" { target c++17_only } } |
| 106 | |
| 107 | const volatile auto b3 = std::bind<int>(X(), _1, 0, _2); |
| 108 | VERIFY( b3(0, 0) == 3 ); // { dg-warning "deprecated" "" { target c++17_only } } |
| 109 | #endif |
| 110 | } |
| 111 | |
| 112 | |
| 113 | int main() |
| 114 | { |
| 115 | test01(); |
| 116 | test02(); |
| 117 | test03(); |
| 118 | test04(); |
| 119 | return 0; |
| 120 | } |