]>
Commit | Line | Data |
---|---|---|
52066eae | 1 | // { dg-do run { target c++11 } } |
7a90b0ca | 2 | |
7adcbafe | 3 | // Copyright (C) 2008-2022 Free Software Foundation, Inc. |
7a90b0ca PC |
4 | // |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the | |
7 | // terms of the GNU General Public License as published by the | |
748086b7 | 8 | // Free Software Foundation; either version 3, or (at your option) |
7a90b0ca PC |
9 | // any later version. |
10 | // | |
11 | // This library is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License along | |
748086b7 JJ |
17 | // with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
7a90b0ca PC |
19 | |
20 | #include <functional> | |
21 | #include <type_traits> | |
22 | #include <testsuite_hooks.h> | |
23 | #include <testsuite_tr1.h> | |
24 | ||
25 | using namespace __gnu_test; | |
26 | ||
7a90b0ca PC |
27 | struct X |
28 | { | |
29 | typedef int result_type; | |
30 | ||
31 | X() : bar(17) {} | |
32 | ||
33 | int foo(float x) { return truncate_float(x); } | |
34 | int foo_c(float x) const { return truncate_float(x); } | |
35 | int foo_v(float x) volatile { return truncate_float(x); } | |
36 | int foo_cv(float x) const volatile { return truncate_float(x); } | |
be7f7822 | 37 | int foo_varargs(float x, ...) { return truncate_float(x); } |
7a90b0ca PC |
38 | |
39 | int operator()(float x) | |
40 | { | |
41 | return foo(x) + 1; | |
42 | } | |
43 | ||
44 | int operator()(float x) const | |
45 | { | |
46 | return foo_c(x) + 2; | |
47 | } | |
48 | ||
49 | int bar; | |
50 | ||
51 | private: | |
52 | X(const X&); | |
53 | X& operator=(const X&); | |
54 | }; | |
55 | ||
56 | int seventeen() { return 17; } | |
57 | ||
58 | struct get_seventeen | |
59 | { | |
60 | typedef int result_type; | |
61 | int operator()() const { return 17; } | |
62 | }; | |
63 | ||
64 | void test01() | |
65 | { | |
66 | using std::ref; | |
67 | using std::cref; | |
68 | ||
69 | ::get_seventeen get_sev; | |
70 | ::X x; | |
be7f7822 JW |
71 | ::X* xp = &x; |
72 | int (::X::* p_foo)(float) = &::X::foo; | |
73 | int (::X::* p_foo_c)(float) const = &::X::foo_c; | |
74 | int (::X::* p_foo_v)(float) volatile = &::X::foo_v; | |
75 | int (::X::* p_foo_cv)(float) const volatile = &::X::foo_cv; | |
b1e282ca | 76 | int (::X::* p_foo_varargs)(float, ...) = &::X::foo_varargs; |
be7f7822 | 77 | int ::X::* p_bar = &::X::bar; |
7a90b0ca PC |
78 | |
79 | const float pi = 3.14; | |
80 | ||
81 | // Functions | |
82 | VERIFY(ref(truncate_float)(pi) == 3); | |
83 | VERIFY(ref(seventeen)() == 17); | |
84 | ||
85 | // Function pointers | |
be7f7822 JW |
86 | VERIFY(cref(truncate_float)(pi) == 3); |
87 | VERIFY(cref(seventeen)() == 17); | |
88 | ||
89 | // Member function pointers | |
90 | VERIFY(ref(p_foo)(x, pi) == 3); | |
91 | VERIFY(ref(p_foo)(xp, pi) == 3); | |
92 | VERIFY(ref(p_foo_c)(x, pi) == 3); | |
93 | VERIFY(ref(p_foo_c)(xp, pi) == 3); | |
94 | VERIFY(ref(p_foo_v)(x, pi) == 3); | |
95 | VERIFY(ref(p_foo_v)(xp, pi) == 3); | |
96 | VERIFY(ref(p_foo_cv)(x, pi) == 3); | |
97 | VERIFY(ref(p_foo_cv)(xp, pi) == 3); | |
b1e282ca JW |
98 | VERIFY(ref(p_foo_varargs)(x, pi) == 3); |
99 | VERIFY(ref(p_foo_varargs)(xp, pi, 1, 1) == 3); | |
100 | VERIFY(ref(p_foo_varargs)(x, pi, 1, 1) == 3); | |
101 | VERIFY(ref(p_foo_varargs)(xp, pi) == 3); | |
be7f7822 JW |
102 | |
103 | // Member data pointers | |
104 | VERIFY(ref(p_bar)(x) == 17); | |
105 | VERIFY(ref(p_bar)(xp) == 17); | |
7a90b0ca | 106 | |
7a90b0ca PC |
107 | // Function objects |
108 | VERIFY(ref(get_sev)() == 17); | |
109 | VERIFY(cref(get_sev)() == 17); | |
110 | VERIFY(ref(x)(pi) == 4); | |
111 | VERIFY(cref(x)(pi) == 5); | |
112 | } | |
113 | ||
114 | int main() | |
115 | { | |
116 | test01(); | |
117 | return 0; | |
118 | } |