1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2019-2020 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
34 ByRef (const ByRef
&rhs
);
44 ByRef::ByRef (const ByRef
&rhs
)
46 x
= 3; /* ByRef-cctor */
49 class ArrayContainerByVal
{
55 cbvArrayContainerByVal (ArrayContainerByVal arg
)
57 arg
.items
[0].x
+= 4; // intentionally modify
58 return arg
.items
[0].x
;
61 class ArrayContainerByRef
{
67 cbvArrayContainerByRef (ArrayContainerByRef arg
)
69 arg
.items
[0].x
+= 4; // intentionally modify
70 return arg
.items
[0].x
;
77 virtual int get (void);
82 DynamicBase::DynamicBase (void)
88 DynamicBase::get (void)
93 class Dynamic
: public DynamicBase
{
95 virtual int get (void);
105 cbvDynamic (DynamicBase arg
)
107 arg
.x
+= 4; // intentionally modify
108 return arg
.x
+ arg
.get ();
115 __attribute__((always_inline
))
116 Inlined (const Inlined
&rhs
)
124 Inlined::Inlined (void)
130 cbvInlined (Inlined arg
)
132 arg
.x
+= 4; // intentionally modify
140 ~DtorDel (void) = delete;
145 DtorDel::DtorDel (void)
151 cbvDtorDel (DtorDel arg
)
153 // Calling this method should be rejected
161 FourCCtor (FourCCtor
&rhs
);
162 FourCCtor (const FourCCtor
&rhs
);
163 FourCCtor (volatile FourCCtor
&rhs
);
164 FourCCtor (const volatile FourCCtor
&rhs
);
169 FourCCtor::FourCCtor (void)
174 FourCCtor::FourCCtor (FourCCtor
&rhs
)
179 FourCCtor::FourCCtor (const FourCCtor
&rhs
)
184 FourCCtor::FourCCtor (volatile FourCCtor
&rhs
)
189 FourCCtor::FourCCtor (const volatile FourCCtor
&rhs
)
195 cbvFourCCtor (FourCCtor arg
)
197 arg
.x
+= 10; // intentionally modify
205 /* Even though one move ctor is defaulted, the other
207 TwoMCtor (const TwoMCtor
&&rhs
);
208 TwoMCtor (TwoMCtor
&&rhs
) = default;
213 TwoMCtor::TwoMCtor (void)
218 TwoMCtor::TwoMCtor (const TwoMCtor
&&rhs
)
224 cbvTwoMCtor (TwoMCtor arg
)
226 arg
.x
+= 10; // intentionally modify
230 class TwoMCtorAndCCtor
{
232 TwoMCtorAndCCtor (void);
234 TwoMCtorAndCCtor (const TwoMCtorAndCCtor
&rhs
) = default;
236 /* Even though one move ctor is defaulted, the other
237 is explicit. This makes the type pass-by-ref. */
238 TwoMCtorAndCCtor (const TwoMCtorAndCCtor
&&rhs
);
239 TwoMCtorAndCCtor (TwoMCtorAndCCtor
&&rhs
) = default;
244 TwoMCtorAndCCtor::TwoMCtorAndCCtor (void)
249 TwoMCtorAndCCtor::TwoMCtorAndCCtor (const TwoMCtorAndCCtor
&&rhs
)
255 cbvTwoMCtorAndCCtor (TwoMCtorAndCCtor arg
)
257 arg
.x
+= 10; // intentionally modify
261 ArrayContainerByVal arrayContainerByVal
;
262 ArrayContainerByRef arrayContainerByRef
;
265 // Cannot stack-allocate DtorDel
267 FourCCtor fourCctor_c0v0
;
268 const FourCCtor fourCctor_c1v0
;
269 volatile FourCCtor fourCctor_c0v1
;
270 const volatile FourCCtor fourCctor_c1v1
;
272 TwoMCtorAndCCtor twoMctorAndCctor
;
278 dtorDel
= new DtorDel
;
279 /* Explicitly call the cbv function to make sure the compiler
280 will not omit any code in the binary. */
281 v
= cbvArrayContainerByVal (arrayContainerByVal
);
282 v
= cbvArrayContainerByRef (arrayContainerByRef
);
283 v
= cbvDynamic (dynamic
);
284 v
= cbvInlined (inlined
);
285 v
= cbvFourCCtor (fourCctor_c0v0
);
286 v
= cbvFourCCtor (fourCctor_c1v0
);
287 v
= cbvFourCCtor (fourCctor_c0v1
);
288 v
= cbvFourCCtor (fourCctor_c1v1
);
289 /* v = cbvTwoMCtor (twoMctor); */ // This is illegal, cctor is deleted
290 v
= cbvTwoMCtorAndCCtor (twoMctorAndCctor
);