Debian Codegraph @

clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp

raw
1 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -verify=cxx23,new %s
2 // RUN: %clang_cc1 -std=c++23 -fsyntax-only -fms-compatibility -verify=cxx23,old %s
3 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify=cxx20,old %s
4
5 // FIXME: This is a test for a temporary workaround where we disable simpler implicit moves
6 // in the STL when compiling with -fms-compatibility, because of issues with the
7 // implementation there.
8 // Feel free to delete this file when the workaround is not needed anymore.
9
10 #if __INCLUDE_LEVEL__ == 0
11
12 #if __cpluscplus > 202002L && __cpp_implicit_move < 202207L
13 #error "__cpp_implicit_move not defined correctly"
14 #endif
15
16 struct nocopy {
17 nocopy(nocopy &&);
18 };
19
20 int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
21 int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
22 nocopy mt3(nocopy x) { return x; }
23
24 namespace {
25 int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
26 int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
27 nocopy mt3(nocopy x) { return x; }
28 } // namespace
29
30 namespace foo {
31 int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
32 int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
33 namespace std {
34 int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
35 int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
36 nocopy mt3(nocopy x) { return x; }
37 } // namespace std
38 } // namespace foo
39
40 namespace std {
41
42 int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
43 int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
44 nocopy mt3(nocopy x) { return x; }
45
46 namespace {
47 int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
48 int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
49 nocopy mt3(nocopy x) { return x; }
50 } // namespace
51
52 namespace foo {
53 int &&mt1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
54 int &mt2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
55 nocopy mt3(nocopy x) { return x; }
56 } // namespace foo
57
58 } // namespace std
59
60 #include __FILE__
61
62 #define SYSTEM
63 #include __FILE__
64
65 #elif !defined(SYSTEM)
66
67 int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
68 int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
69 nocopy ut3(nocopy x) { return x; }
70
71 namespace {
72 int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
73 int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
74 nocopy ut3(nocopy x) { return x; }
75 } // namespace
76
77 namespace foo {
78 int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
79 int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
80 nocopy ut3(nocopy x) { return x; }
81 namespace std {
82 int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
83 int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
84 nocopy ut3(nocopy x) { return x; }
85 } // namespace std
86 } // namespace foo
87
88 namespace std {
89
90 int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
91 int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
92 nocopy ut3(nocopy x) { return x; }
93
94 namespace {
95 int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
96 int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
97 nocopy ut3(nocopy x) { return x; }
98 } // namespace
99
100 namespace foo {
101 int &&ut1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
102 int &ut2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
103 nocopy ut3(nocopy x) { return x; }
104 } // namespace foo
105
106 } // namespace std
107
108 #else
109
110 #pragma GCC system_header
111
112 int &&st1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
113 int &st2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
114 nocopy st3(nocopy x) { return x; }
115
116 namespace {
117 int &&st1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
118 int &st2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
119 nocopy st3(nocopy x) { return x; }
120 } // namespace
121
122 namespace foo {
123 int &&st1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
124 int &st2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
125 nocopy st3(nocopy x) { return x; }
126 namespace std {
127 int &&st1(int &&x) { return x; } // cxx20-error {{cannot bind to lvalue}}
128 int &st2(int &&x) { return x; } // cxx23-error {{cannot bind to a temporary}}
129 nocopy st3(nocopy x) { return x; }
130 } // namespace std
131 } // namespace foo
132
133 namespace std {
134
135 int &&st1(int &&x) { return x; } // old-error {{cannot bind to lvalue}}
136 int &st2(int &&x) { return x; } // new-error {{cannot bind to a temporary}}
137 nocopy st3(nocopy x) { return x; }
138
139 namespace {
140 int &&st1(int &&x) { return x; } // old-error {{cannot bind to lvalue}}
141 int &st2(int &&x) { return x; } // new-error {{cannot bind to a temporary}}
142 nocopy st3(nocopy x) { return x; }
143 } // namespace
144
145 namespace foo {
146 int &&st1(int &&x) { return x; } // old-error {{cannot bind to lvalue}}
147 int &st2(int &&x) { return x; } // new-error {{cannot bind to a temporary}}
148 nocopy st3(nocopy x) { return x; }
149 } // namespace foo
150
151 } // namespace std
152
153 #endif