Commit | Line | Data |
---|---|---|
c0f55cc6 AV |
1 | /* This testcase is part of GDB, the GNU debugger. |
2 | ||
e2882c85 | 3 | Copyright 1998-2018 Free Software Foundation, Inc. |
c0f55cc6 AV |
4 | |
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. | |
9 | ||
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. | |
14 | ||
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/>. */ | |
17 | ||
18 | /* Rvalue references overload tests for GDB, based on overload.cc. */ | |
19 | ||
20 | #include <stddef.h> | |
21 | #include <utility> | |
22 | ||
23 | class foo; | |
24 | ||
25 | typedef foo &foo_lval_ref; | |
26 | typedef foo &&foo_rval_ref; | |
27 | ||
28 | class foo | |
29 | { | |
30 | public: | |
31 | foo (); | |
32 | foo (foo_lval_ref); | |
33 | foo (foo_rval_ref); | |
34 | ~foo (); | |
35 | ||
36 | int overload1arg (foo_lval_ref); | |
37 | int overload1arg (foo_rval_ref); | |
38 | }; | |
39 | ||
40 | void | |
41 | marker1 () | |
42 | { | |
43 | } | |
44 | ||
45 | static int | |
46 | f (int &x) | |
47 | { | |
48 | return 1; | |
49 | } | |
50 | ||
51 | static int | |
52 | f (const int &x) | |
53 | { | |
54 | return 2; | |
55 | } | |
56 | ||
57 | static int | |
58 | f (int &&x) | |
59 | { | |
60 | return 3; | |
61 | } | |
62 | ||
63 | int | |
64 | main () | |
65 | { | |
66 | foo foo_rr_instance1; | |
67 | foo arg; | |
68 | int i = 0; | |
69 | const int ci = 0; | |
70 | ||
71 | // result = 1 + 2 + 3 + 3 = 9 | |
72 | int result = f (i) + f (ci) + f (0) + f (std::move (i)); | |
73 | ||
74 | marker1 (); // marker1-returns-here | |
75 | return result; | |
76 | } | |
77 | ||
78 | foo::foo () {} | |
79 | foo::foo (foo_lval_ref afoo) {} | |
80 | foo::foo (foo_rval_ref afoo) {} | |
81 | foo::~foo () {} | |
82 | ||
83 | /* Some functions to test overloading by varying one argument type. */ | |
84 | ||
85 | int foo::overload1arg (foo_lval_ref arg) { return 1; } | |
86 | int foo::overload1arg (foo_rval_ref arg) { return 2; } |