1 // { dg-do compile { target c++11 } }
2 
3 // Copyright (C) 2008-2021 Free Software Foundation, Inc.
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
8 // Free Software Foundation; either version 3, or (at your option)
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
17 // with this library; see the file COPYING3.  If not see
18 // <http://www.gnu.org/licenses/>.
19 
20 
21 #include <functional>
22 
23 struct test_type
24 {
25    int member();
26    int cmember()const;
27    int member2(char);
28    int cmember2(char)const;
29 };
30 
31 struct functor1 : public std::unary_function<int, double>
32 {
33   double operator()(int) const;
34 };
35 
36 struct functor2 : public std::binary_function<int, char, double>
37 {
38    double operator()(int, char) const;
39 };
40 
41 template <class T>
verify_return_type(T,T)42 void verify_return_type(T, T)
43 {
44 }
45 
test01()46 void test01()
47 {
48   test_type* null_tt = 0;
49   const test_type* null_ttc = 0;
50   int zero;
51 
52   std::reference_wrapper<double (int)>* pr1(0);
53   verify_return_type((*pr1)(0), double());
54   std::reference_wrapper<double (*)(int)>* pr2(0);
55   verify_return_type((*pr2)(0), double());
56   std::reference_wrapper<int (test_type::*)()>* pr3(0);
57   verify_return_type((*pr3)(null_tt), int());
58   std::reference_wrapper<int (test_type::*)()const>* pr4(0);
59   verify_return_type((*pr4)(null_ttc), int());
60   std::reference_wrapper<functor1>* pr5(0);
61 
62   // libstdc++/24803
63   verify_return_type((*pr5)(0), double());
64   verify_return_type((*pr5)(zero), double());
65 
66   std::reference_wrapper<double (int, char)>* pr1b(0);
67   verify_return_type((*pr1b)(0, 0), double());
68   std::reference_wrapper<double (*)(int, char)>* pr2b(0);
69   verify_return_type((*pr2b)(0, 0), double());
70   std::reference_wrapper<int (test_type::*)(char)>* pr3b(0);
71   verify_return_type((*pr3b)(null_tt,zero), int());
72   std::reference_wrapper<int (test_type::*)()const>* pr4b(0);
73   verify_return_type((*pr4b)(null_ttc), int());
74   std::reference_wrapper<functor2>* pr5b(0);
75 
76   // libstdc++/24803
77   verify_return_type((*pr5b)(0, 0), double());
78   verify_return_type((*pr5b)(zero, zero), double());
79 }
80