]> gcc.gnu.org Git - gcc.git/blame - libstdc++-v3/testsuite/20_util/bind/cv_quals.cc
libstdc++: Disable volatile-qualified std::bind for C++20
[gcc.git] / libstdc++-v3 / testsuite / 20_util / bind / cv_quals.cc
CommitLineData
7adcbafe 1// Copyright (C) 2010-2022 Free Software Foundation, Inc.
8232dc64
PC
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
d01f112d 20// { dg-options "-Wdeprecated-declarations" }
52066eae 21// { dg-do run { target c++11 } }
8232dc64
PC
22
23#include <functional>
24#include <testsuite_hooks.h>
25
1b3fad81
JW
26// target must be invoked with cv-quals of call wrapper
27
8232dc64
PC
28struct X
29{
30 int operator()() { return 0; }
31 int operator()() const { return 1; }
1b3fad81
JW
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; }
8232dc64
PC
39};
40
1b3fad81
JW
41using std::placeholders::_1;
42using std::placeholders::_2;
43
8232dc64
PC
44void test01()
45{
8232dc64
PC
46 auto b0 = std::bind(X());
47 VERIFY( b0() == 0 );
48
49 const auto b1 = std::bind(X());
50 VERIFY( b1() == 1 );
51
d01f112d 52#if __cplusplus <= 201703L
1b3fad81 53 volatile auto b2 = std::bind(X());
d01f112d 54 VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } }
1b3fad81
JW
55
56 const volatile auto b3 = std::bind(X());
d01f112d 57 VERIFY( b3() == 3 ); // { dg-warning "deprecated" "" { target c++17_only } }
de1d0794 58#endif
1b3fad81
JW
59}
60
61void test02()
62{
1b3fad81
JW
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
d01f112d 69#if __cplusplus <= 201703L
1b3fad81 70 volatile auto b2 = std::bind<int>(X());
d01f112d 71 VERIFY( b2() == 2 ); // { dg-warning "deprecated" "" { target c++17_only } }
1b3fad81
JW
72
73 const volatile auto b3 = std::bind<int>(X());
d01f112d 74 VERIFY( b3() == 3 ); // { dg-warning "deprecated" "" { target c++17_only } }
de1d0794 75#endif
1b3fad81
JW
76}
77
78void test03()
79{
1b3fad81
JW
80 auto b0 = std::bind(X(), 0, _1, _2);
81 VERIFY( b0(0, 0) == 0 );
8232dc64 82
1b3fad81
JW
83 const auto b1 = std::bind(X(), _1, 0, _2);
84 VERIFY( b1(0, 0) == 1 );
85
d01f112d 86#if __cplusplus <= 201703L
1b3fad81 87 volatile auto b2 = std::bind(X(), _1, _2, 0);
d01f112d 88 VERIFY( b2(0, 0) == 2 ); // { dg-warning "deprecated" "" { target c++17_only } }
1b3fad81
JW
89
90 const volatile auto b3 = std::bind(X(), _1, 0, _2);
d01f112d 91 VERIFY( b3(0, 0) == 3 ); // { dg-warning "deprecated" "" { target c++17_only } }
de1d0794 92#endif
8232dc64
PC
93}
94
1b3fad81
JW
95void test04()
96{
1b3fad81
JW
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
d01f112d 103#if __cplusplus <= 201703L
1b3fad81 104 volatile auto b2 = std::bind<int>(X(), _1, _2, 0);
d01f112d 105 VERIFY( b2(0, 0) == 2 ); // { dg-warning "deprecated" "" { target c++17_only } }
1b3fad81
JW
106
107 const volatile auto b3 = std::bind<int>(X(), _1, 0, _2);
d01f112d 108 VERIFY( b3(0, 0) == 3 ); // { dg-warning "deprecated" "" { target c++17_only } }
de1d0794 109#endif
1b3fad81
JW
110}
111
112
8232dc64
PC
113int main()
114{
115 test01();
1b3fad81
JW
116 test02();
117 test03();
118 test04();
8232dc64
PC
119 return 0;
120}
This page took 1.379831 seconds and 5 git commands to generate.