1
- // RUN: %clang_cc1 -std=c++17 -verify %s
2
- // RUN: %clang_cc1 -std=c++17 -verify %s -DNO_CONSTEXPR
3
- // RUN: %clang_cc1 -std=c++20 -verify %s
1
+ // RUN: %clang_cc1 -std=c++17 -verify=cxx17,expected %s
2
+ // RUN: %clang_cc1 -std=c++17 -verify=cxx17,expected %s -DNO_CONSTEXPR
3
+ // RUN: %clang_cc1 -std=c++20 -verify=cxx20,expected %s
4
4
5
5
namespace std {
6
6
#ifndef NO_CONSTEXPR
@@ -12,6 +12,7 @@ namespace std {
12
12
template <typename T> CONSTEXPR T &&move(T &x) {
13
13
static_assert (T::moveable, " instantiated move" ); // expected-error {{no member named 'moveable' in 'B'}}
14
14
// expected-error@-1 {{no member named 'moveable' in 'C'}}
15
+ // expected-error@-2 {{no member named 'moveable' in 'D'}}
15
16
return static_cast <T&&>(x);
16
17
}
17
18
@@ -23,6 +24,7 @@ namespace std {
23
24
24
25
template <typename T> CONSTEXPR auto move_if_noexcept (T &x) -> typename ref<T, noexcept (T(static_cast <T&&>(x)))>::type {
25
26
static_assert (T::moveable, " instantiated move_if_noexcept" ); // expected-error {{no member named 'moveable' in 'B'}}
27
+ // expected-error@-1 {{no member named 'moveable' in 'D'}}
26
28
return static_cast <typename ref<T, noexcept (T (static_cast <T&&>(x)))>::type>(x);
27
29
}
28
30
@@ -36,6 +38,7 @@ namespace std {
36
38
template <typename T> CONSTEXPR T &&forward(typename remove_reference<T>::type &x) {
37
39
static_assert (T::moveable, " instantiated forward" ); // expected-error {{no member named 'moveable' in 'B'}}
38
40
// expected-error@-1 {{no member named 'moveable' in 'C'}}
41
+ // expected-error@-2 {{no member named 'moveable' in 'D'}}
39
42
return static_cast <T&&>(x);
40
43
}
41
44
template <typename T> CONSTEXPR T &&forward(typename remove_reference<T>::type &&x) {
@@ -67,21 +70,25 @@ namespace std {
67
70
CONSTEXPR auto forward_like (T &&t) -> ForwardLikeRetType<U, T> {
68
71
using TT = typename remove_reference<T>::type;
69
72
static_assert (TT::moveable, " instantiated as_const" ); // expected-error {{no member named 'moveable' in 'B'}}
73
+ // expected-error@-1 {{no member named 'moveable' in 'D'}}
70
74
return static_cast <ForwardLikeRetType<U, T>>(t);
71
75
}
72
76
73
77
template <typename T> CONSTEXPR const T &as_const (T &x) {
74
78
static_assert (T::moveable, " instantiated as_const" ); // expected-error {{no member named 'moveable' in 'B'}}
79
+ // expected-error@-1 {{no member named 'moveable' in 'D'}}
75
80
return x;
76
81
}
77
82
78
83
template <typename T> CONSTEXPR T *addressof (T &x) {
79
84
static_assert (T::moveable, " instantiated addressof" ); // expected-error {{no member named 'moveable' in 'B'}}
85
+ // expected-error@-1 {{no member named 'moveable' in 'D'}}
80
86
return __builtin_addressof (x);
81
87
}
82
88
83
89
template <typename T> CONSTEXPR T *__addressof (T &x) {
84
90
static_assert (T::moveable, " instantiated __addressof" ); // expected-error {{no member named 'moveable' in 'B'}}
91
+ // expected-error@-1 {{no member named 'moveable' in 'D'}}
85
92
return __builtin_addressof (x);
86
93
}
87
94
}
@@ -116,42 +123,20 @@ A &forward_rval_as_lval() {
116
123
}
117
124
118
125
struct B {};
119
- B &&(*pMove)(B&) = std::move; // #1 expected-note {{instantiation of}}
120
- B &&(*pMoveIfNoexcept)(B&) = &std::move_if_noexcept; // #2 expected-note {{instantiation of}}
121
- B &&(*pForward)(B&) = &std::forward<B>; // #3 expected-note {{instantiation of}}
122
- B &&(*pForwardLike)(B&) = &std::forward_like<int &&, B&>; // #4 expected-note {{instantiation of}}
123
- const B &(*pAsConst)(B&) = &std::as_const; // #5 expected-note {{instantiation of}}
124
- B *(*pAddressof)(B&) = &std::addressof; // #6 expected-note {{instantiation of}}
125
- B *(*pUnderUnderAddressof)(B&) = &std::__addressof; // #7 expected-note {{instantiation of}}
126
+ B &&(*pMove)(B&) = std::move; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
127
+ B &&(*pMoveIfNoexcept)(B&) = &std::move_if_noexcept; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
128
+ B &&(*pForward)(B&) = &std::forward<B>; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
129
+ B &&(*pForwardLike)(B&) = &std::forward_like<int &&, B&>; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
130
+ const B &(*pAsConst)(B&) = &std::as_const; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
131
+ B *(*pAddressof)(B&) = &std::addressof; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
132
+ B *(*pUnderUnderAddressof)(B&) = &std::__addressof; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
126
133
int (*pUnrelatedMove)(B, B) = std::move;
127
134
128
135
struct C {};
129
- C &&(&rMove)(C&) = std::move; // #8 expected-note {{instantiation of}}
130
- C &&(&rForward)(C&) = std::forward<C>; // #9 expected-note {{instantiation of}}
136
+ C &&(&rMove)(C&) = std::move; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
137
+ C &&(&rForward)(C&) = std::forward<C>; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
131
138
int (&rUnrelatedMove)(B, B) = std::move;
132
139
133
- #if __cplusplus <= 201703L
134
- // expected-warning@#1 {{non-addressable}}
135
- // expected-warning@#2 {{non-addressable}}
136
- // expected-warning@#3 {{non-addressable}}
137
- // expected-warning@#4 {{non-addressable}}
138
- // expected-warning@#5 {{non-addressable}}
139
- // expected-warning@#6 {{non-addressable}}
140
- // expected-warning@#7 {{non-addressable}}
141
- // expected-warning@#8 {{non-addressable}}
142
- // expected-warning@#9 {{non-addressable}}
143
- #else
144
- // expected-error@#1 {{non-addressable}}
145
- // expected-error@#2 {{non-addressable}}
146
- // expected-error@#3 {{non-addressable}}
147
- // expected-error@#4 {{non-addressable}}
148
- // expected-error@#5 {{non-addressable}}
149
- // expected-error@#6 {{non-addressable}}
150
- // expected-error@#7 {{non-addressable}}
151
- // expected-error@#8 {{non-addressable}}
152
- // expected-error@#9 {{non-addressable}}
153
- #endif
154
-
155
140
void attribute_const () {
156
141
int n;
157
142
std::move (n); // expected-warning {{ignoring return value}}
@@ -163,6 +148,22 @@ void attribute_const() {
163
148
std::as_const (n); // expected-warning {{ignoring return value}}
164
149
}
165
150
151
+ struct D {
152
+ void * operator new (__SIZE_TYPE__, D&&(*)(D&));
153
+ void * operator new (__SIZE_TYPE__, D*(*)(D&));
154
+ void * operator new (__SIZE_TYPE__, const D&(*)(D&));
155
+ };
156
+
157
+ void placement_new () {
158
+ new (std::move<D>) D; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
159
+ new (std::move_if_noexcept<D>) D; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
160
+ new (std::forward<D>) D; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
161
+ new (std::forward_like<D>) D; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
162
+ new (std::addressof<D>) D; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
163
+ new (std::__addressof<D>) D; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
164
+ new (std::as_const<D>) D; // cxx17-warning {{non-addressable}} cxx20-error {{non-addressable}} expected-note {{instantiation of}}
165
+ }
166
+
166
167
namespace std {
167
168
template <typename T> int &move (T);
168
169
}
0 commit comments