]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/function/invoke/forwarding.cc
libstdc++: Disable hosted-only tests [PR103626]
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / function / invoke / forwarding.cc
1 // Copyright (C) 2014-2022 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 // { dg-do run { target c++11 } }
19 // { dg-require-effective-target hosted }
20
21 #include <functional>
22 #include <testsuite_hooks.h>
23
24 struct Counted
25 {
26 Counted() : count(0) { }
27 Counted(const Counted& c) : count(c.count + 1) { }
28 int count;
29 };
30
31 int func(Counted c) { return c.count; }
32
33 std::function<int(Counted)> f = func;
34
35 void
36 test01()
37 {
38 Counted c;
39 int n = f(c);
40 // 1 copy invoking function::operator() and 1 copy invoking func
41 VERIFY( n == 2 );
42 }
43
44 void
45 test02()
46 {
47 int n = f(Counted{});
48 // copy elided when invoking function::operator(), 1 copy invoking func
49 VERIFY( n == 1 );
50 }
51
52 int
53 main()
54 {
55 test01();
56 test02();
57 }