Reverting merge from trunk
[official-gcc.git] / libstdc++-v3 / testsuite / 20_util / function_objects / mem_fn / 55463.cc
blobc6a6a4e6749157f2d26f71e7d0645ec75733d274
1 // { dg-options "-std=gnu++11" }
2 // { dg-do compile }
4 // Copyright (C) 2012-2013 Free Software Foundation, Inc.
5 //
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 3, or (at your option)
10 // any later version.
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING3. If not see
19 // <http://www.gnu.org/licenses/>.
21 // PR libstdc++/55463 Passing rvalue objects to std::mem_fn
23 #include <functional>
25 struct X
27 int& func();
28 char& func_c() const;
29 short& func_v() volatile;
30 double& func_cv() const volatile;
32 int data;
35 struct Y : X { };
37 using CX = const X;
38 using CY = const Y;
40 using X_ptr = X*;
42 struct smart_ptr
44 X& operator*() const;
47 std::reference_wrapper<X> ref();
48 std::reference_wrapper<const X> cref();
49 std::reference_wrapper<Y> yref();
51 void test01()
53 int& i1 __attribute__((unused)) = std::mem_fn( &X::func )( X() );
54 int& i2 __attribute__((unused)) = std::mem_fn( &X::func )( Y() );
55 int& i3 __attribute__((unused)) = std::mem_fn( &X::func )( ref() );
56 int& i4 __attribute__((unused)) = std::mem_fn( &X::func )( yref() );
57 int& i5 __attribute__((unused)) = std::mem_fn( &X::func )( X_ptr() );
58 int& i6 __attribute__((unused)) = std::mem_fn( &X::func )( smart_ptr() );
60 char& c1 __attribute__((unused)) = std::mem_fn( &X::func_c )( X() );
61 char& c2 __attribute__((unused)) = std::mem_fn( &X::func_c )( CX() );
62 char& c3 __attribute__((unused)) = std::mem_fn( &X::func_c )( Y() );
63 char& c4 __attribute__((unused)) = std::mem_fn( &X::func_c )( ref() );
64 char& c5 __attribute__((unused)) = std::mem_fn( &X::func_c )( cref() );
65 char& c6 __attribute__((unused)) = std::mem_fn( &X::func_c )( yref() );
66 char& c7 __attribute__((unused)) = std::mem_fn( &X::func_c )( X_ptr() );
67 char& c8 __attribute__((unused)) = std::mem_fn( &X::func_c )( smart_ptr() );
69 short& s1 __attribute__((unused)) = std::mem_fn( &X::func_v )( X() );
70 short& s2 __attribute__((unused)) = std::mem_fn( &X::func_v )( Y() );
71 short& s3 __attribute__((unused)) = std::mem_fn( &X::func_v )( ref() );
72 short& s4 __attribute__((unused)) = std::mem_fn( &X::func_v )( yref() );
73 short& s5 __attribute__((unused)) = std::mem_fn( &X::func_v )( X_ptr() );
74 short& s6 __attribute__((unused)) = std::mem_fn( &X::func_v )( smart_ptr() );
76 double& d1 __attribute__((unused)) = std::mem_fn( &X::func_cv )( X() );
77 double& d2 __attribute__((unused)) = std::mem_fn( &X::func_cv )( CX() );
78 double& d3 __attribute__((unused)) = std::mem_fn( &X::func_cv )( Y() );
79 double& d4 __attribute__((unused)) = std::mem_fn( &X::func_cv )( ref() );
80 double& d5 __attribute__((unused)) = std::mem_fn( &X::func_cv )( cref() );
81 double& d6 __attribute__((unused)) = std::mem_fn( &X::func_cv )( yref() );
82 double& d7 __attribute__((unused)) = std::mem_fn( &X::func_cv )( X_ptr() );
83 double& d8 __attribute__((unused))
84 = std::mem_fn( &X::func_cv )( smart_ptr() );
86 // [expr.mptr.oper]
87 // The result of a .* expression whose second operand is a pointer to a
88 // data member is of the same value category (3.10) as its first operand.
89 int&& rval __attribute__((unused)) = std::mem_fn( &X::data )( X() );
90 const int&& crval __attribute__((unused)) = std::mem_fn( &X::data )( CX() );
91 int&& yrval __attribute__((unused)) = std::mem_fn( &X::data )( Y() );
92 const int&& ycrval __attribute__((unused)) = std::mem_fn( &X::data )( CY() );
94 int& val __attribute__((unused)) = std::mem_fn( &X::data )( ref() );
95 const int& cval __attribute__((unused)) = std::mem_fn( &X::data )( cref() );
96 int& yval __attribute__((unused)) = std::mem_fn( &X::data )( yref() );
98 int& pval __attribute__((unused)) = std::mem_fn( &X::data )( X_ptr() );
99 int& sval __attribute__((unused)) = std::mem_fn( &X::data )( smart_ptr() );
102 void test02()
104 std::reference_wrapper<X> r = ref();
105 X& x1 __attribute__((unused))
106 = std::mem_fn( &std::reference_wrapper<X>::get )( r );
107 const std::reference_wrapper<X> cr = ref();
108 const X& x3 __attribute__((unused))
109 = std::mem_fn( &std::reference_wrapper<X>::get )( cr );
110 X& x2 __attribute__((unused))
111 = std::mem_fn( &std::reference_wrapper<X>::get )( ref() );