| 1 |
/* PR rtl-optimization/23585 */ |
| 2 |
/* Testcase by Matti Rintala <[email protected]> */ |
| 3 |
|
| 4 |
/* { dg-do run } */ |
| 5 |
/* { dg-options "-O2" } */ |
| 6 |
|
| 7 |
template <class _Ret, class _Tp> |
| 8 |
class const_mem_fun_t |
| 9 |
{ |
| 10 |
public: |
| 11 |
explicit |
| 12 |
const_mem_fun_t(_Ret (_Tp::*__pf)() const) |
| 13 |
: _M_f(__pf) {} |
| 14 |
|
| 15 |
_Ret |
| 16 |
operator()(const _Tp* __p) const |
| 17 |
{ return (__p->*_M_f)(); } |
| 18 |
private: |
| 19 |
_Ret (_Tp::*_M_f)() const; |
| 20 |
}; |
| 21 |
|
| 22 |
template <class _Ret, class _Tp> |
| 23 |
class const_mem_fun_ref_t |
| 24 |
{ |
| 25 |
public: |
| 26 |
explicit |
| 27 |
const_mem_fun_ref_t(_Ret (_Tp::*__pf)() const) |
| 28 |
: _M_f(__pf) {} |
| 29 |
|
| 30 |
_Ret |
| 31 |
operator()(const _Tp& __r) const |
| 32 |
{ return (__r.*_M_f)(); } |
| 33 |
private: |
| 34 |
_Ret (_Tp::*_M_f)() const; |
| 35 |
}; |
| 36 |
|
| 37 |
template <class _Ret, class _Tp, class _Arg> |
| 38 |
class const_mem_fun1_t |
| 39 |
{ |
| 40 |
public: |
| 41 |
explicit |
| 42 |
const_mem_fun1_t(_Ret (_Tp::*__pf)(_Arg) const) |
| 43 |
: _M_f(__pf) {} |
| 44 |
|
| 45 |
_Ret |
| 46 |
operator()(const _Tp* __p, _Arg __x) const |
| 47 |
{ return (__p->*_M_f)(__x); } |
| 48 |
private: |
| 49 |
_Ret (_Tp::*_M_f)(_Arg) const; |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
template <class _Ret, class _Tp, class _Arg> |
| 54 |
class const_mem_fun1_ref_t |
| 55 |
{ |
| 56 |
public: |
| 57 |
explicit |
| 58 |
const_mem_fun1_ref_t(_Ret (_Tp::*__pf)(_Arg) const) |
| 59 |
: _M_f(__pf) {} |
| 60 |
|
| 61 |
_Ret |
| 62 |
operator()(const _Tp& __r, _Arg __x) const |
| 63 |
{ return (__r.*_M_f)(__x); } |
| 64 |
private: |
| 65 |
_Ret (_Tp::*_M_f)(_Arg) const; |
| 66 |
}; |
| 67 |
|
| 68 |
template <class _Ret, class _Tp> |
| 69 |
inline const_mem_fun_t<_Ret, _Tp> |
| 70 |
mem_fun(_Ret (_Tp::*__f)() const) |
| 71 |
{ return const_mem_fun_t<_Ret, _Tp>(__f); } |
| 72 |
|
| 73 |
template <class _Ret, class _Tp> |
| 74 |
inline const_mem_fun_ref_t<_Ret, _Tp> |
| 75 |
mem_fun_ref(_Ret (_Tp::*__f)() const) |
| 76 |
{ return const_mem_fun_ref_t<_Ret, _Tp>(__f); } |
| 77 |
|
| 78 |
template <class _Ret, class _Tp, class _Arg> |
| 79 |
inline const_mem_fun1_t<_Ret, _Tp, _Arg> |
| 80 |
mem_fun(_Ret (_Tp::*__f)(_Arg) const) |
| 81 |
{ return const_mem_fun1_t<_Ret, _Tp, _Arg>(__f); } |
| 82 |
|
| 83 |
template <class _Ret, class _Tp, class _Arg> |
| 84 |
inline const_mem_fun1_ref_t<_Ret, _Tp, _Arg> |
| 85 |
mem_fun_ref(_Ret (_Tp::*__f)(_Arg) const) |
| 86 |
{ return const_mem_fun1_ref_t<_Ret, _Tp, _Arg>(__f); } |
| 87 |
|
| 88 |
class Klasse { |
| 89 |
public: |
| 90 |
void vf0c() const; |
| 91 |
void vf1c(const int&) const; |
| 92 |
}; |
| 93 |
|
| 94 |
int main() |
| 95 |
{ |
| 96 |
Klasse obj; |
| 97 |
const Klasse& objc = obj; |
| 98 |
|
| 99 |
mem_fun(&Klasse::vf0c)(&objc); |
| 100 |
mem_fun(&Klasse::vf1c)(&objc, 1); |
| 101 |
|
| 102 |
mem_fun_ref(&Klasse::vf0c)(objc); |
| 103 |
mem_fun_ref(&Klasse::vf1c)(objc, 1); |
| 104 |
return 0; |
| 105 |
} |
| 106 |
|
| 107 |
void Klasse::vf0c() const |
| 108 |
{} |
| 109 |
|
| 110 |
void Klasse::vf1c(const int&) const |
| 111 |
{} |