aboutsummaryrefslogtreecommitdiff
path: root/Examples/test-suite/cpp11_ref_qualifiers.i
blob: e37136770e5ca67fedfa775fc56c2ffb40e0ba8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
%module cpp11_ref_qualifiers

%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra2;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) ccextra3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc2;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc3;
%warnfilter(SWIGWARN_TYPEMAP_SWIGTYPELEAK_MSG) cc5;

%include <std_string.i>

%ignore Host::h() const &;

// Basic testing
%inline %{
using std::string;
class Host {
  string s;
public:
  string h1() & { return string(); }
  string h2() const & { return string(); }
  string h3() && { return std::move(string()); }
  string h4() const && { return std::move(string()); }
  string h5() const { return string(); }
  string h6() volatile const & { return string(); }
  string h7() const volatile & { return string(); }
  string h8() volatile const && { return std::move(string()); }
  string h9() const volatile && { return std::move(string()); }

  string h() & { return string(); }
  string h() const & { return string(); }
  string h() && { return std::move(string()); }
  string h() const && { return std::move(string()); }
};
%}

// %feature testing
%feature("except") F1() & %{ result = "F1"; %}
%feature("except") F2 %{ result = "F2"; %}
%feature("except") F3 %{ result = "F3"; %}
%feature("except") F3() %{ _should_not_be_used_ %}

%feature("except") C1(int i) const & %{ result = "C1"; %}
%feature("except") C2 %{ result = "C2"; %}
%feature("except") C3 %{ result = "C3"; %}
%feature("except") C3(int i) %{ _should_not_be_used_ %}

%inline %{
struct Features {
  string F1() & { return string(); }
  string F2() & { return string(); }
  string F3() & { return string(); }

  string C1(int i) const & { return string(); }
  string C2(int i) const & { return string(); }
  string C3(int i) const & { return string(); }
};
%}

// %rename testing
%rename(RR1) R1;
%rename(RR2) R2() &;
%rename(RR3) R3;
%rename(RR3Bad) R3();

%rename(SS1) S1;
%rename(SS2) S2(int i) const &;
%rename(SS3) S3;
%rename(SS3Bad) S3(int i);
%rename(SS3BadConst) S3(int i) const;
%rename(SS3BadLValue) S3(int i) &;

%inline %{
struct Renames {
  string R1() & { return string(); }
  string R2() & { return string(); }
  string R3() & { return string(); }

  string S1(int i) const & { return string(); }
  string S2(int i) const & { return string(); }
  string S3(int i) const & { return string(); }
};
%}

// Conversion operators
%rename(StringConvertCopy) operator string() &;
%rename(StringConvertMove) operator string() &&;
%feature("ignore", "0") operator string() &&; // unignore as it is ignored by default

%inline %{
struct ConversionOperators {
  virtual operator string() & { return string(); }
  virtual operator string() && { return std::move(string()); }
  virtual ~ConversionOperators() {}
};
struct ConversionOperators2 {
  virtual operator string() && { return std::move(string()); }
  virtual ~ConversionOperators2() {}
};
%}

%inline %{
struct Funcs {
  short FF(bool) { return 0; }
  short CC(bool) const & { return 0; }
};

class MemberFuncPtrs
{
public:
  // member ref-qualified function pointers, unnamed parameters
  int aaa1(short (Funcs::*)(bool) &) const;
  int aaa2(short (Funcs::* const *&)(bool) &) const;
  int aaa3(short (Funcs::* *&)(bool) &) const;
  int aaa4(short (Funcs::* *const&)(bool) &) const;
  int aaa5(short (Funcs::* &)(bool) &) const;
  int aaa6(short (Funcs::* const)(bool) &) const;
  int aaa7(short (Funcs::* const&)(bool) &) const;

  int aaa8(short (Funcs::* const&)(bool) &&) const;

  // member cv-qualified and ref-qualified function pointers, unnamed parameters
  int bbb1(short (Funcs::*)(bool) const &) const;
  int bbb2(short (Funcs::* const *&)(bool) const &) const;
  int bbb3(short (Funcs::* *&)(bool) const &) const;
  int bbb4(short (Funcs::* *const&)(bool) const &) const;
  int bbb5(short (Funcs::* &)(bool) const &) const;
  int bbb6(short (Funcs::* const)(bool) const &) const;
  int bbb7(short (Funcs::* const&)(bool) const &) const;

  int bbb8(short (Funcs::*)(bool) const &&) const;

  // member ref-qualified function pointers, named parameters
  int qqq1(short (Funcs::* qq1)(bool) &) const;
  int qqq2(short (Funcs::* const *& qq2)(bool) &) const;
  int qqq3(short (Funcs::* *& qq3)(bool) &) const;
  int qqq4(short (Funcs::* *const& qq4)(bool) &) const;
  int qqq5(short (Funcs::* & qq5)(bool) &) const;
  int qqq6(short (Funcs::* const qq6)(bool) &) const;
  int qqq7(short (Funcs::* const& qq7)(bool) &) const;

  int qqq8(short (Funcs::* const& qq8)(bool) &&) const;

  // member cv-qualified and ref-qualified function pointers, named parameters
  int rrr1(short (Funcs::* rr1)(bool) const &) const;
  int rrr2(short (Funcs::* const *& rr2)(bool) const &) const;
  int rrr3(short (Funcs::* *& rr3)(bool) const &) const;
  int rrr4(short (Funcs::* *const& rr4)(bool) const &) const;
  int rrr5(short (Funcs::* & rr5)(bool) const &) const;
  int rrr6(short (Funcs::* const rr6)(bool) const &) const;
  int rrr7(short (Funcs::* const& rr7)(bool) const &) const;

  int rrr8(short (Funcs::* rr1)(bool) const &&) const;
};

// member ref-qualified function pointers, unnamed parameters
int MemberFuncPtrs::aaa1(short (Funcs::*)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa2(short (Funcs::* const *&)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa3(short (Funcs::* *&)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa4(short (Funcs::* *const&)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa5(short (Funcs::* &)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa6(short (Funcs::* const)(bool) &) const { return 0; }
int MemberFuncPtrs::aaa7(short (Funcs::* const&)(bool) &) const { return 0; }

int MemberFuncPtrs::aaa8(short (Funcs::* const&)(bool) &&) const { return 0; }

// member cv-qualified and ref-qualified function pointers, unnamed parameters
int MemberFuncPtrs::bbb1(short (Funcs::*)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb2(short (Funcs::* const *&)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb3(short (Funcs::* *&)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb4(short (Funcs::* *const&)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb5(short (Funcs::* &)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb6(short (Funcs::* const)(bool) const &) const { return 0; }
int MemberFuncPtrs::bbb7(short (Funcs::* const&)(bool) const &) const { return 0; }

int MemberFuncPtrs::bbb8(short (Funcs::*)(bool) const &&) const { return 0; }

// member ref-qualified function pointers, named parameters
int MemberFuncPtrs::qqq1(short (Funcs::* qq1)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq2(short (Funcs::* const *& qq2)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq3(short (Funcs::* *& qq3)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq4(short (Funcs::* *const& qq4)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq5(short (Funcs::* & qq5)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq6(short (Funcs::* const qq6)(bool) &) const { return 0; }
int MemberFuncPtrs::qqq7(short (Funcs::* const& qq7)(bool) &) const { return 0; }

int MemberFuncPtrs::qqq8(short (Funcs::* const& qq8)(bool) &&) const { return 0; }

// member cv-qualified and ref-qualified function pointers, named parameters
int MemberFuncPtrs::rrr1(short (Funcs::* rr1)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr2(short (Funcs::* const *& rr2)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr3(short (Funcs::* *& rr3)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr4(short (Funcs::* *const& rr4)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr5(short (Funcs::* & rr5)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr6(short (Funcs::* const rr6)(bool) const &) const { return 0; }
int MemberFuncPtrs::rrr7(short (Funcs::* const& rr7)(bool) const &) const { return 0; }

int MemberFuncPtrs::rrr8(short (Funcs::* rr1)(bool) const &&) const { return 0; }

// member cv-qualified and ref-qualified pointer variables
short (Funcs::* cc1)(bool) const & = &Funcs::CC;

short (Funcs::* const * ccextra2)(bool) const & = &cc1;
short (Funcs::* * ccextra3)(bool) const & = &cc1;
short (Funcs::* *const ccextra4)(bool) const & = &cc1;

short (Funcs::* const *& cc2)(bool) const & = ccextra2;
short (Funcs::* *& cc3)(bool) const & = ccextra3;
short (Funcs::* *const& cc4)(bool) const & = ccextra4;
short (Funcs::* & cc5)(bool) const & = cc1;
short (Funcs::* const cc6)(bool) const & = &Funcs::CC;
short (Funcs::* const& cc7)(bool) const & = cc1;
%}

%inline %{

struct Funktions {
  int addByValue(const int &a, int b) const & { return a+b; }
  int * addByPointer(const int &a, int b) const & { static int val; val = a+b; return &val; }
  int & addByReference(const int &a, int b) const & { static int val; val = a+b; return val; }
};

int call1(int (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
//int call2(int * (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return *(f.*d)(a, b); }
//int call3(int & (Funktions::*d)(const int &, int) const &, int a, int b) { Funktions f; return (f.*d)(a, b); }
%}
%constant int (Funktions::*ADD_BY_VALUE)(const int &, int) const & = &Funktions::addByValue;