| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -Wno-vla-cxx-extension -Wno-c++26-extensions -std=c++20 %s |
| 2 |
|
| 3 |
struct S : A {}; // expected-error{{expected class name}} |
| 4 |
|
| 5 |
static_assert(__builtin_is_cpp_trivially_relocatable()); // expected-error {{expected a type}} |
| 6 |
static_assert(__builtin_is_cpp_trivially_relocatable(0)); // expected-error {{expected a type}} |
| 7 |
static_assert(__builtin_is_cpp_trivially_relocatable(S)); |
| 8 |
static_assert(__builtin_is_cpp_trivially_relocatable(A)); // expected-error{{unknown type name 'A'}} |
| 9 |
|
| 10 |
static_assert(__builtin_is_cpp_trivially_relocatable(int, int)); // expected-error {{type trait requires 1 argument; have 2 arguments}} |
| 11 |
|
| 12 |
static_assert(__builtin_is_cpp_trivially_relocatable(int&)); |
| 13 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(int &)'}} \ |
| 14 |
// expected-note@-1 {{'int &' is not trivially relocatable}} \ |
| 15 |
// expected-note@-1 {{because it is a reference type}} |
| 16 |
|
| 17 |
|
| 18 |
static_assert(!__builtin_is_cpp_trivially_relocatable(int&)); |
| 19 |
static_assert(!!__builtin_is_cpp_trivially_relocatable(int&)); |
| 20 |
// expected-error@-1{{static assertion failed due to requirement '!!__builtin_is_cpp_trivially_relocatable(int &)'}} |
| 21 |
static_assert(bool(__builtin_is_cpp_trivially_relocatable(int&))); |
| 22 |
// expected-error@-1{{static assertion failed due to requirement 'bool(__builtin_is_cpp_trivially_relocatable(int &))'}} |
| 23 |
|
| 24 |
static_assert(__builtin_is_cpp_trivially_relocatable(int&) && __builtin_is_cpp_trivially_relocatable(int&)); |
| 25 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(int &)'}} \ |
| 26 |
// expected-note@-1 {{'int &' is not trivially relocatable}} \ |
| 27 |
// expected-note@-1 {{because it is a reference type}} |
| 28 |
|
| 29 |
namespace concepts { |
| 30 |
template <typename T> |
| 31 |
requires __builtin_is_cpp_trivially_relocatable(T) void f(); // #cand1 |
| 32 |
|
| 33 |
template <typename T> |
| 34 |
concept C = __builtin_is_cpp_trivially_relocatable(T); // #concept2 |
| 35 |
|
| 36 |
template <C T> void g(); // #cand2 |
| 37 |
|
| 38 |
void test() { |
| 39 |
f<int&>(); |
| 40 |
// expected-error@-1 {{no matching function for call to 'f'}} \ |
| 41 |
// expected-note@#cand1 {{candidate template ignored: constraints not satisfied [with T = int &]}} \ |
| 42 |
// expected-note@#cand1 {{because '__builtin_is_cpp_trivially_relocatable(int &)' evaluated to false}} \ |
| 43 |
// expected-note@#cand1 {{'int &' is not trivially relocatable}} \ |
| 44 |
// expected-note@#cand1 {{because it is a reference type}} |
| 45 |
|
| 46 |
g<int&>(); |
| 47 |
// expected-error@-1 {{no matching function for call to 'g'}} \ |
| 48 |
// expected-note@#cand2 {{candidate template ignored: constraints not satisfied [with T = int &]}} \ |
| 49 |
// expected-note@#cand2 {{because 'int &' does not satisfy 'C'}} \ |
| 50 |
// expected-note@#concept2 {{because '__builtin_is_cpp_trivially_relocatable(int &)' evaluated to false}} \ |
| 51 |
// expected-note@#concept2 {{'int &' is not trivially relocatable}} \ |
| 52 |
// expected-note@#concept2 {{because it is a reference type}} |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
namespace trivially_relocatable { |
| 57 |
|
| 58 |
extern int vla_size; |
| 59 |
static_assert(__builtin_is_cpp_trivially_relocatable(int[vla_size])); |
| 60 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(int[vla_size])'}} \ |
| 61 |
// expected-note@-1 {{'int[vla_size]' is not trivially relocatable}} \ |
| 62 |
// expected-note@-1 {{because it is a variably-modified type}} |
| 63 |
|
| 64 |
struct S; // expected-note {{forward declaration of 'trivially_relocatable::S'}} |
| 65 |
static_assert(__builtin_is_cpp_trivially_relocatable(S)); |
| 66 |
// expected-error@-1 {{incomplete type 'S' used in type trait expression}} |
| 67 |
|
| 68 |
struct B { |
| 69 |
virtual ~B(); |
| 70 |
}; |
| 71 |
struct S : virtual B { // #tr-S |
| 72 |
S(); |
| 73 |
int & a; |
| 74 |
const int ci; |
| 75 |
B & b; |
| 76 |
B c; |
| 77 |
~S(); |
| 78 |
}; |
| 79 |
static_assert(__builtin_is_cpp_trivially_relocatable(S)); |
| 80 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(trivially_relocatable::S)'}} \ |
| 81 |
// expected-note@-1 {{'S' is not trivially relocatable}} \ |
| 82 |
// expected-note@-1 {{because it has a virtual base 'B'}} \ |
| 83 |
// expected-note@-1 {{because it has a non-trivially-relocatable base 'B'}} \ |
| 84 |
// expected-note@-1 {{because it has a non-trivially-relocatable member 'c' of type 'B'}} \ |
| 85 |
// expected-note@-1 {{because it has a user-provided destructor}} |
| 86 |
// expected-note@#tr-S {{'S' defined here}} |
| 87 |
|
| 88 |
struct S2 { // #tr-S2 |
| 89 |
S2(S2&&); |
| 90 |
S2& operator=(const S2&); |
| 91 |
}; |
| 92 |
static_assert(__builtin_is_cpp_trivially_relocatable(S2)); |
| 93 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(trivially_relocatable::S2)'}} \ |
| 94 |
// expected-note@-1 {{'S2' is not trivially relocatable}} \ |
| 95 |
// expected-note@-1 {{because it has a user provided move constructor}} \ |
| 96 |
// expected-note@-1 {{because it has a user provided copy assignment operator}} \ |
| 97 |
// expected-note@#tr-S2 {{'S2' defined here}} |
| 98 |
|
| 99 |
|
| 100 |
struct S3 { // #tr-S3 |
| 101 |
~S3() = delete; |
| 102 |
}; |
| 103 |
static_assert(__builtin_is_cpp_trivially_relocatable(S3)); |
| 104 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(trivially_relocatable::S3)'}} \ |
| 105 |
// expected-note@-1 {{'S3' is not trivially relocatable}} \ |
| 106 |
// expected-note@-1 {{because it has a deleted destructor}} \ |
| 107 |
// expected-note@#tr-S3 {{'S3' defined here}} |
| 108 |
|
| 109 |
|
| 110 |
union U { // #tr-U |
| 111 |
U(const U&); |
| 112 |
U(U&&); |
| 113 |
U& operator=(const U&); |
| 114 |
U& operator=(U&&); |
| 115 |
}; |
| 116 |
static_assert(__builtin_is_cpp_trivially_relocatable(U)); |
| 117 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(trivially_relocatable::U)'}} \ |
| 118 |
// expected-note@-1 {{'U' is not trivially relocatable}} \ |
| 119 |
// expected-note@-1 {{because it is a union with a user-declared copy constructor}} \ |
| 120 |
// expected-note@-1 {{because it is a union with a user-declared copy assignment operator}} \ |
| 121 |
// expected-note@-1 {{because it is a union with a user-declared move constructor}} \ |
| 122 |
// expected-note@-1 {{because it is a union with a user-declared move assignment operator}} |
| 123 |
// expected-note@#tr-U {{'U' defined here}} |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
namespace GH143325 { |
| 128 |
struct Foo { // expected-note {{previous definition is here}} |
| 129 |
Foo(const Foo&); |
| 130 |
~Foo(); |
| 131 |
}; |
| 132 |
|
| 133 |
struct Foo { // expected-error {{redefinition of 'Foo'}} |
| 134 |
Foo(); |
| 135 |
int; |
| 136 |
}; |
| 137 |
struct Wrapper { // #GH143325-Wrapper |
| 138 |
union { |
| 139 |
Foo p; |
| 140 |
} u; |
| 141 |
}; |
| 142 |
|
| 143 |
static_assert(__builtin_is_cpp_trivially_relocatable(Wrapper)); |
| 144 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(GH143325::Wrapper)'}} \ |
| 145 |
// expected-note@-1 {{'Wrapper' is not trivially relocatable}} \ |
| 146 |
// expected-note@-1 {{because it has a non-trivially-relocatable member 'u' of type 'union}} \ |
| 147 |
// expected-note@-1 {{because it has a deleted destructor}} |
| 148 |
// expected-note@#GH143325-Wrapper {{'Wrapper' defined here}} |
| 149 |
|
| 150 |
struct Polymorphic { |
| 151 |
virtual ~Polymorphic(); |
| 152 |
}; |
| 153 |
|
| 154 |
struct UnionOfPolymorphic { // #GH143325-UnionOfPolymorphic |
| 155 |
union { |
| 156 |
Polymorphic p; |
| 157 |
int i; |
| 158 |
} u; |
| 159 |
}; |
| 160 |
|
| 161 |
static_assert(__builtin_is_cpp_trivially_relocatable(UnionOfPolymorphic)); |
| 162 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(GH143325::UnionOfPolymorphic)'}} \ |
| 163 |
// expected-note@-1 {{'UnionOfPolymorphic' is not trivially relocatable}} \ |
| 164 |
// expected-note@-1 {{because it has a non-trivially-relocatable member 'u' of type 'union}} \ |
| 165 |
// expected-note@-1 {{because it has a deleted destructor}} \ |
| 166 |
// expected-note@#GH143325-UnionOfPolymorphic {{'UnionOfPolymorphic' defined here}} |
| 167 |
|
| 168 |
} |
| 169 |
|
| 170 |
struct GH143599 { // expected-note {{'GH143599' defined here}} |
| 171 |
~GH143599 (); |
| 172 |
GH143599(const GH143599&); |
| 173 |
GH143599& operator=(const GH143599&); |
| 174 |
}; |
| 175 |
GH143599::~GH143599 () = default; |
| 176 |
GH143599::GH143599 (const GH143599&) = default; |
| 177 |
GH143599& GH143599::operator=(const GH143599&) = default; |
| 178 |
|
| 179 |
static_assert (__builtin_is_cpp_trivially_relocatable(GH143599)); |
| 180 |
// expected-error@-1 {{static assertion failed due to requirement '__builtin_is_cpp_trivially_relocatable(GH143599)'}} \ |
| 181 |
// expected-note@-1 {{'GH143599' is not trivially relocatable}} \ |
| 182 |
// expected-note@-1 {{because it has a user provided copy constructor}} \ |
| 183 |
// expected-note@-1 {{because it has a user provided copy assignment operator}} \ |
| 184 |
// expected-note@-1 {{because it has a user-provided destructor}} |
| 185 |
|
| 186 |
namespace trivially_copyable { |
| 187 |
struct B { |
| 188 |
virtual ~B(); |
| 189 |
}; |
| 190 |
struct S : virtual B { // #tc-S |
| 191 |
S(); |
| 192 |
int & a; |
| 193 |
const int ci; |
| 194 |
B & b; |
| 195 |
B c; |
| 196 |
~S(); |
| 197 |
}; |
| 198 |
static_assert(__is_trivially_copyable(S)); |
| 199 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S)'}} \ |
| 200 |
// expected-note@-1 {{'S' is not trivially copyable}} \ |
| 201 |
// expected-note@-1 {{because it has a virtual base 'B'}} \ |
| 202 |
// expected-note@-1 {{because it has a non-trivially-copyable base 'B'}} \ |
| 203 |
// expected-note@-1 {{because it has a non-trivially-copyable member 'c' of type 'B'}} \ |
| 204 |
// expected-note@-1 {{because it has a non-trivially-copyable member 'b' of type 'B &'}} \ |
| 205 |
// expected-note@-1 {{because it has a non-trivially-copyable member 'a' of type 'int &'}} \ |
| 206 |
// expected-note@-1 {{because it has a user-provided destructor}} |
| 207 |
// expected-note@#tc-S {{'S' defined here}} |
| 208 |
|
| 209 |
struct S2 { // #tc-S2 |
| 210 |
S2(S2&&); |
| 211 |
S2& operator=(const S2&); |
| 212 |
}; |
| 213 |
static_assert(__is_trivially_copyable(S2)); |
| 214 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S2)'}} \ |
| 215 |
// expected-note@-1 {{'S2' is not trivially copyable}} \ |
| 216 |
// expected-note@-1 {{because it has a user provided move constructor}} \ |
| 217 |
// expected-note@-1 {{because it has a user provided copy assignment operator}} \ |
| 218 |
// expected-note@#tc-S2 {{'S2' defined here}} |
| 219 |
|
| 220 |
struct S3 { |
| 221 |
~S3() = delete; |
| 222 |
}; |
| 223 |
static_assert(__is_trivially_copyable(S3)); |
| 224 |
|
| 225 |
struct S4 { // #tc-S4 |
| 226 |
~S4(); |
| 227 |
B b; |
| 228 |
}; |
| 229 |
static_assert(__is_trivially_copyable(S4)); |
| 230 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S4)'}} \ |
| 231 |
// expected-note@-1 {{'S4' is not trivially copyable}} \ |
| 232 |
// expected-note@-1 {{because it has a non-trivially-copyable member 'b' of type 'B'}} \ |
| 233 |
// expected-note@-1 {{because it has a user-provided destructor}} \ |
| 234 |
// expected-note@#tc-S4 {{'S4' defined here}} |
| 235 |
|
| 236 |
struct B1 { |
| 237 |
int & a; |
| 238 |
}; |
| 239 |
|
| 240 |
struct B2 { |
| 241 |
int & a; |
| 242 |
}; |
| 243 |
|
| 244 |
struct S5 : virtual B1, virtual B2 { // #tc-S5 |
| 245 |
}; |
| 246 |
static_assert(__is_trivially_copyable(S5)); |
| 247 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S5)'}} \ |
| 248 |
// expected-note@-1 {{'S5' is not trivially copyable}} \ |
| 249 |
// expected-note@-1 {{because it has a virtual base 'B1'}} \ |
| 250 |
// expected-note@-1 {{because it has a virtual base 'B2'}} \ |
| 251 |
// expected-note@#tc-S5 {{'S5' defined here}} |
| 252 |
|
| 253 |
struct B3 { |
| 254 |
~B3(); |
| 255 |
}; |
| 256 |
|
| 257 |
struct B4 { |
| 258 |
~B4(); |
| 259 |
}; |
| 260 |
|
| 261 |
struct S6 : B3, B4 { // #tc-S6 |
| 262 |
}; |
| 263 |
static_assert(__is_trivially_copyable(S6)); |
| 264 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S6)'}} \ |
| 265 |
// expected-note@-1 {{because it has a non-trivially-copyable base 'B3'}} \ |
| 266 |
// expected-note@-1 {{because it has a non-trivially-copyable base 'B4'}} \ |
| 267 |
// expected-note@-1 {{because it has a user-provided destructor}} \ |
| 268 |
// expected-note@-1 {{'S6' is not trivially copyable}} \ |
| 269 |
// expected-note@#tc-S6 {{'S6' defined here}} |
| 270 |
|
| 271 |
struct S7 { // #tc-S7 |
| 272 |
S7(const S7&); |
| 273 |
}; |
| 274 |
static_assert(__is_trivially_copyable(S7)); |
| 275 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S7)'}} \ |
| 276 |
// expected-note@-1 {{because it has a user provided copy constructor}} \ |
| 277 |
// expected-note@-1 {{'S7' is not trivially copyable}} \ |
| 278 |
// expected-note@#tc-S7 {{'S7' defined here}} |
| 279 |
|
| 280 |
struct S8 { // #tc-S8 |
| 281 |
S8(S8&&); |
| 282 |
}; |
| 283 |
static_assert(__is_trivially_copyable(S8)); |
| 284 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S8)'}} \ |
| 285 |
// expected-note@-1 {{because it has a user provided move constructor}} \ |
| 286 |
// expected-note@-1 {{'S8' is not trivially copyable}} \ |
| 287 |
// expected-note@#tc-S8 {{'S8' defined here}} |
| 288 |
|
| 289 |
struct S9 { // #tc-S9 |
| 290 |
S9& operator=(const S9&); |
| 291 |
}; |
| 292 |
static_assert(__is_trivially_copyable(S9)); |
| 293 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S9)'}} \ |
| 294 |
// expected-note@-1 {{because it has a user provided copy assignment operator}} \ |
| 295 |
// expected-note@-1 {{'S9' is not trivially copyable}} \ |
| 296 |
// expected-note@#tc-S9 {{'S9' defined here}} |
| 297 |
|
| 298 |
struct S10 { // #tc-S10 |
| 299 |
S10& operator=(S10&&); |
| 300 |
}; |
| 301 |
static_assert(__is_trivially_copyable(S10)); |
| 302 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S10)'}} \ |
| 303 |
// expected-note@-1 {{because it has a user provided move assignment operator}} \ |
| 304 |
// expected-note@-1 {{'S10' is not trivially copyable}} \ |
| 305 |
// expected-note@#tc-S10 {{'S10' defined here}} |
| 306 |
|
| 307 |
struct B5 : B4 { |
| 308 |
}; |
| 309 |
|
| 310 |
struct B6 : B5 { |
| 311 |
}; |
| 312 |
|
| 313 |
struct S11 : B6 { // #tc-S11 |
| 314 |
}; |
| 315 |
static_assert(__is_trivially_copyable(S11)); |
| 316 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S11)'}} \ |
| 317 |
// expected-note@-1 {{because it has a non-trivially-copyable base 'B6'}} \ |
| 318 |
// expected-note@-1 {{'S11' is not trivially copyable}} \ |
| 319 |
// expected-note@#tc-S11 {{'S11' defined here}} |
| 320 |
|
| 321 |
struct S12 : B6 { // #tc-S12 |
| 322 |
~S12() = delete; |
| 323 |
}; |
| 324 |
static_assert(__is_trivially_copyable(S12)); |
| 325 |
// expected-error@-1 {{static assertion failed due to requirement '__is_trivially_copyable(trivially_copyable::S12)'}} \ |
| 326 |
// expected-note@-1 {{because it has a non-trivially-copyable base 'B6'}} \ |
| 327 |
// expected-note@-1 {{because it has a deleted destructor}} \ |
| 328 |
// expected-note@-1 {{'S12' is not trivially copyable}} \ |
| 329 |
// expected-note@#tc-S12 {{'S12' defined here}} |
| 330 |
} |
| 331 |
|
| 332 |
namespace constructible { |
| 333 |
|
| 334 |
struct S1 { // #c-S1 |
| 335 |
S1(int); // #cc-S1 |
| 336 |
}; |
| 337 |
static_assert(__is_constructible(S1, char*)); |
| 338 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(constructible::S1, char *)'}} \ |
| 339 |
// expected-error@-1 {{no matching constructor for initialization of 'S1'}} \ |
| 340 |
// expected-note@#c-S1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'char *' to 'const S1' for 1st argument}} \ |
| 341 |
// expected-note@#c-S1 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'char *' to 'S1' for 1st argument}} \ |
| 342 |
// expected-note@#cc-S1 {{candidate constructor not viable: no known conversion from 'char *' to 'int' for 1st argument; dereference the argument with *}} \ |
| 343 |
// expected-note@#c-S1 {{'S1' defined here}} |
| 344 |
|
| 345 |
struct S2 { // #c-S2 |
| 346 |
S2(int, float, double); // #cc-S2 |
| 347 |
}; |
| 348 |
static_assert(__is_constructible(S2, float)); |
| 349 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(constructible::S2, float)'}} \ |
| 350 |
// expected-note@#c-S2 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'float' to 'const S2' for 1st argument}} \ |
| 351 |
// expected-note@#c-S2 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'float' to 'S2' for 1st argument}} \ |
| 352 |
// expected-error@-1 {{no matching constructor for initialization of 'S2'}} \ |
| 353 |
// expected-note@#cc-S2 {{candidate constructor not viable: requires 3 arguments, but 1 was provided}} \ |
| 354 |
// expected-note@#c-S2 {{'S2' defined here}} |
| 355 |
|
| 356 |
static_assert(__is_constructible(S2, float, void)); |
| 357 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(constructible::S2, float, void)'}} \ |
| 358 |
// expected-note@#c-S2 {{candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided}} \ |
| 359 |
// expected-note@#c-S2 {{candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided}} \ |
| 360 |
// expected-note@-1{{because it is a cv void type}} \ |
| 361 |
// expected-error@-1 {{no matching constructor for initialization of 'S2'}} \ |
| 362 |
// expected-note@#cc-S2 {{candidate constructor not viable: requires 3 arguments, but 2 were provided}} \ |
| 363 |
// expected-note@#c-S2 {{'S2' defined here}} |
| 364 |
|
| 365 |
static_assert(__is_constructible(int[])); |
| 366 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(int[])'}} \ |
| 367 |
// expected-note@-1 {{because it is an incomplete array type}} |
| 368 |
|
| 369 |
static_assert(__is_constructible(void)); |
| 370 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(void)'}} \ |
| 371 |
// expected-note@-1 {{because it is a cv void type}} |
| 372 |
|
| 373 |
static_assert(__is_constructible(void, void)); |
| 374 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(void, void)'}} \ |
| 375 |
// expected-note@-1 {{because it is a cv void type}} |
| 376 |
|
| 377 |
static_assert(__is_constructible(const void)); |
| 378 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(const void)'}} \ |
| 379 |
// expected-note@-1 {{because it is a cv void type}} |
| 380 |
|
| 381 |
static_assert(__is_constructible(volatile void)); |
| 382 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(volatile void)'}} \ |
| 383 |
// expected-note@-1 {{because it is a cv void type}} |
| 384 |
|
| 385 |
static_assert(__is_constructible(int ())); |
| 386 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(int ())'}} \ |
| 387 |
// expected-note@-1 {{because it is a function type}} |
| 388 |
|
| 389 |
static_assert(__is_constructible(void (int, float))); |
| 390 |
// expected-error@-1 {{static assertion failed due to requirement '__is_constructible(void (int, float))'}} \ |
| 391 |
// expected-note@-1 {{because it is a function type}} |
| 392 |
} |
| 393 |
|
| 394 |
namespace assignable { |
| 395 |
struct S1; |
| 396 |
static_assert(__is_assignable(S1&, const S1&)); |
| 397 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(assignable::S1 &, const assignable::S1 &)'}} \ |
| 398 |
// expected-error@-1 {{no viable overloaded '='}} \ |
| 399 |
// expected-note@-1 {{type 'S1' is incomplete}} |
| 400 |
|
| 401 |
static_assert(__is_assignable(void, int)); |
| 402 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(void, int)'}} \ |
| 403 |
// expected-error@-1 {{expression is not assignable}} |
| 404 |
|
| 405 |
static_assert(__is_assignable(int, int)); |
| 406 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(int, int)'}} \ |
| 407 |
// expected-error@-1 {{expression is not assignable}} |
| 408 |
|
| 409 |
static_assert(__is_assignable(int*, int)); |
| 410 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(int *, int)'}} \ |
| 411 |
// expected-error@-1 {{expression is not assignable}} |
| 412 |
|
| 413 |
static_assert(__is_assignable(int[], int)); |
| 414 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(int[], int)'}} \ |
| 415 |
// expected-error@-1 {{expression is not assignable}} |
| 416 |
|
| 417 |
static_assert(__is_assignable(int&, void)); |
| 418 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(int &, void)'}} \ |
| 419 |
// expected-error@-1 {{assigning to 'int' from incompatible type 'void'}} |
| 420 |
|
| 421 |
static_assert(__is_assignable(int*&, float*)); |
| 422 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(int *&, float *)'}} \ |
| 423 |
// expected-error@-1 {{incompatible pointer types assigning to 'int *' from 'float *'}} |
| 424 |
|
| 425 |
static_assert(__is_assignable(const int&, int)); |
| 426 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(const int &, int)'}} \ |
| 427 |
// expected-error@-1 {{read-only variable is not assignable}} |
| 428 |
|
| 429 |
struct S2 {}; // #a-S2 |
| 430 |
static_assert(__is_assignable(const S2, S2)); |
| 431 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(const assignable::S2, assignable::S2)'}} \ |
| 432 |
// expected-error@-1 {{no viable overloaded '='}} \ |
| 433 |
// expected-note@#a-S2 {{candidate function (the implicit copy assignment operator) not viable: 'this' argument has type 'const S2', but method is not marked const}} \ |
| 434 |
// expected-note@#a-S2 {{candidate function (the implicit move assignment operator) not viable: 'this' argument has type 'const S2', but method is not marked const}} \ |
| 435 |
// expected-note@#a-S2 {{'S2' defined here}} |
| 436 |
|
| 437 |
struct S3 { // #a-S3 |
| 438 |
S3& operator=(const S3&) = delete; // #aca-S3 |
| 439 |
S3& operator=(S3&&) = delete; // #ama-S3 |
| 440 |
}; |
| 441 |
static_assert(__is_assignable(S3, const S3&)); |
| 442 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(assignable::S3, const assignable::S3 &)'}} \ |
| 443 |
// expected-error@-1 {{overload resolution selected deleted operator '='}} \ |
| 444 |
// expected-note@#aca-S3 {{candidate function has been explicitly deleted}} \ |
| 445 |
// expected-note@#ama-S3 {{candidate function not viable: 1st argument ('const S3') would lose const qualifier}} \ |
| 446 |
// expected-note@#a-S3 {{'S3' defined here}} |
| 447 |
static_assert(__is_assignable(S3, S3&&)); |
| 448 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(assignable::S3, assignable::S3 &&)'}} \ |
| 449 |
// expected-error@-1 {{overload resolution selected deleted operator '='}} \ |
| 450 |
// expected-note@#aca-S3 {{candidate function has been explicitly deleted}} \ |
| 451 |
// expected-note@#ama-S3 {{candidate function has been explicitly deleted}} \ |
| 452 |
// expected-note@#a-S3 {{'S3' defined here}} |
| 453 |
|
| 454 |
class C1 { // #a-C1 |
| 455 |
C1& operator=(const C1&) = default; |
| 456 |
C1& operator=(C1&&) = default; // #ama-C1 |
| 457 |
}; |
| 458 |
static_assert(__is_assignable(C1, C1)); |
| 459 |
// expected-error@-1 {{static assertion failed due to requirement '__is_assignable(assignable::C1, assignable::C1)'}} \ |
| 460 |
// expected-error@-1 {{'operator=' is a private member of 'assignable::C1'}} \ |
| 461 |
// expected-note@#ama-C1 {{implicitly declared private here}} \ |
| 462 |
// expected-note@#a-C1 {{'C1' defined here}} |
| 463 |
} |
| 464 |
|
| 465 |
namespace is_empty_tests { |
| 466 |
// Non-static data member. |
| 467 |
struct A { int x; }; // #e-A |
| 468 |
static_assert(__is_empty(A)); |
| 469 |
// expected-error@-1 {{static assertion failed due to requirement '__is_empty(is_empty_tests::A)'}} \ |
| 470 |
// expected-note@-1 {{'A' is not empty}} \ |
| 471 |
// expected-note@-1 {{because it has a non-static data member 'x' of type 'int'}} \ |
| 472 |
// expected-note@#e-A {{'A' defined here}} |
| 473 |
|
| 474 |
// Reference member. |
| 475 |
struct R {int &r; }; // #e-R |
| 476 |
static_assert(__is_empty(R)); |
| 477 |
// expected-error@-1 {{static assertion failed due to requirement '__is_empty(is_empty_tests::R)'}} \ |
| 478 |
// expected-note@-1 {{'R' is not empty}} \ |
| 479 |
// expected-note@-1 {{because it has a non-static data member 'r' of type 'int &'}} \ |
| 480 |
// expected-note@#e-R {{'R' defined here}} |
| 481 |
|
| 482 |
// Virtual function. |
| 483 |
struct VirtualFunc {virtual void f(); }; // #e-VirtualFunc |
| 484 |
static_assert(__is_empty(VirtualFunc)); |
| 485 |
// expected-error@-1 {{static assertion failed due to requirement '__is_empty(is_empty_tests::VirtualFunc)'}} \ |
| 486 |
// expected-note@-1 {{'VirtualFunc' is not empty}} \ |
| 487 |
// expected-note@-1 {{because it has a virtual function 'f'}} \ |
| 488 |
// expected-note@#e-VirtualFunc {{'VirtualFunc' defined here}} |
| 489 |
|
| 490 |
// Virtual base class. |
| 491 |
struct EB {}; |
| 492 |
struct VB: virtual EB {}; // #e-VB |
| 493 |
static_assert(__is_empty(VB)); |
| 494 |
// expected-error@-1 {{static assertion failed due to requirement '__is_empty(is_empty_tests::VB)'}} \ |
| 495 |
// expected-note@-1 {{'VB' is not empty}} \ |
| 496 |
// expected-note@-1 {{because it has a virtual base 'EB'}} \ |
| 497 |
// expected-note@#e-VB {{'VB' defined here}} |
| 498 |
|
| 499 |
// Non-empty base class. |
| 500 |
struct Base { int b; }; // #e-Base |
| 501 |
struct Derived : Base {}; // #e-Derived |
| 502 |
static_assert(__is_empty(Derived)); |
| 503 |
// expected-error@-1 {{static assertion failed due to requirement '__is_empty(is_empty_tests::Derived)'}} \ |
| 504 |
// expected-note@-1 {{'Derived' is not empty}} \ |
| 505 |
// expected-note@-1 {{because it has a base class 'Base' that is not empty}} \ |
| 506 |
// expected-note@#e-Derived {{'Derived' defined here}} |
| 507 |
|
| 508 |
// Combination of the above. |
| 509 |
struct Multi : Base, virtual EB { // #e-Multi |
| 510 |
int z; |
| 511 |
virtual void g(); |
| 512 |
}; |
| 513 |
static_assert(__is_empty(Multi)); |
| 514 |
// expected-error@-1 {{static assertion failed due to requirement '__is_empty(is_empty_tests::Multi)'}} \ |
| 515 |
// expected-note@-1 {{'Multi' is not empty}} \ |
| 516 |
// expected-note@-1 {{because it has a non-static data member 'z' of type 'int'}} \ |
| 517 |
// expected-note@-1 {{because it has a virtual function 'g'}} \ |
| 518 |
// expected-note@-1 {{because it has a base class 'Base' that is not empty}} \ |
| 519 |
// expected-note@-1 {{because it has a virtual base 'EB'}} \ |
| 520 |
// expected-note@#e-Multi {{'Multi' defined here}} |
| 521 |
|
| 522 |
// Zero-width bit-field. |
| 523 |
struct BitField { int : 0; }; // #e-BitField |
| 524 |
static_assert(__is_empty(BitField)); // no diagnostics |
| 525 |
|
| 526 |
// Dependent bit-field width. |
| 527 |
template <int N> |
| 528 |
struct DependentBitField { int : N; }; // #e-DependentBitField |
| 529 |
|
| 530 |
static_assert(__is_empty(DependentBitField<0>)); // no diagnostics |
| 531 |
|
| 532 |
static_assert(__is_empty(DependentBitField<2>)); |
| 533 |
// expected-error@-1 {{static assertion failed due to requirement '__is_empty(is_empty_tests::DependentBitField<2>)'}} \ |
| 534 |
// expected-note@-1 {{'DependentBitField<2>' is not empty}} \ |
| 535 |
// expected-note@-1 {{because it field '' is a non-zero-length bit-field}} \ |
| 536 |
// expected-note@#e-DependentBitField {{'DependentBitField<2>' defined here}} |
| 537 |
|
| 538 |
} |
| 539 |
|
| 540 |
namespace standard_layout_tests { |
| 541 |
struct WithVirtual { // #sl-Virtual |
| 542 |
virtual void foo(); // #sl-Virtual-Foo |
| 543 |
}; |
| 544 |
static_assert(__is_standard_layout(WithVirtual)); |
| 545 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::WithVirtual)'}} \ |
| 546 |
// expected-note@-1 {{'WithVirtual' is not standard-layout}} \ |
| 547 |
// expected-note@-1 {{because it has a virtual function 'foo'}} \ |
| 548 |
// expected-note@#sl-Virtual-Foo {{'foo' defined here}} \ |
| 549 |
// expected-note@#sl-Virtual {{'WithVirtual' defined here}} |
| 550 |
|
| 551 |
struct MixedAccess { // #sl-Mixed |
| 552 |
public: |
| 553 |
int a; // #sl-MixedF1 |
| 554 |
private: |
| 555 |
int b; // #sl-MixedF2 |
| 556 |
}; |
| 557 |
static_assert(__is_standard_layout(MixedAccess)); |
| 558 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::MixedAccess)'}} \ |
| 559 |
// expected-note@-1 {{'MixedAccess' is not standard-layout}} \ |
| 560 |
// expected-note@-1 {{because it has mixed access specifiers}} \ |
| 561 |
// expected-note@#sl-MixedF1 {{'a' defined here}} |
| 562 |
// expected-note@#sl-MixedF2 {{field 'b' has a different access specifier than field 'a'}} |
| 563 |
// expected-note@#sl-Mixed {{'MixedAccess' defined here}} |
| 564 |
|
| 565 |
struct VirtualBase { virtual ~VirtualBase(); }; // #sl-VirtualBase |
| 566 |
struct VB : virtual VirtualBase {}; // #sl-VB |
| 567 |
static_assert(__is_standard_layout(VB)); |
| 568 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::VB)'}} \ |
| 569 |
// expected-note@-1 {{'VB' is not standard-layout}} \ |
| 570 |
// expected-note@-1 {{because it has a virtual base 'VirtualBase'}} \ |
| 571 |
// expected-note@-1 {{because it has a non-standard-layout base 'VirtualBase'}} \ |
| 572 |
// expected-note@-1 {{because it has a virtual function '~VB'}} \ |
| 573 |
// expected-note@#sl-VB {{'VB' defined here}} |
| 574 |
// expected-note@#sl-VB {{'~VB' defined here}} |
| 575 |
|
| 576 |
union U { // #sl-U |
| 577 |
public: |
| 578 |
int x; // #sl-UF1 |
| 579 |
private: |
| 580 |
int y; // #sl-UF2 |
| 581 |
}; |
| 582 |
static_assert(__is_standard_layout(U)); |
| 583 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::U)'}} \ |
| 584 |
// expected-note@-1 {{'U' is not standard-layout}} \ |
| 585 |
// expected-note@-1 {{because it has mixed access specifiers}} |
| 586 |
// expected-note@#sl-UF1 {{'x' defined here}} |
| 587 |
// expected-note@#sl-UF2 {{field 'y' has a different access specifier than field 'x'}} |
| 588 |
// expected-note@#sl-U {{'U' defined here}} |
| 589 |
|
| 590 |
// Single base class is OK |
| 591 |
struct BaseClass{ int a; }; // #sl-BaseClass |
| 592 |
struct DerivedOK : BaseClass {}; // #sl-DerivedOK |
| 593 |
static_assert(__is_standard_layout(DerivedOK)); |
| 594 |
|
| 595 |
// Primitive types should be standard layout |
| 596 |
static_assert(__is_standard_layout(int)); // #sl-Int |
| 597 |
static_assert(__is_standard_layout(float)); // #sl-Float |
| 598 |
|
| 599 |
// Multi-level inheritance: Non-standard layout |
| 600 |
struct Base1 { int a; }; // #sl-Base1 |
| 601 |
struct Base2 { int b; }; // #sl-Base2 |
| 602 |
struct DerivedClass : Base1, Base2 {}; // #sl-DerivedClass |
| 603 |
static_assert(__is_standard_layout(DerivedClass)); |
| 604 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::DerivedClass)'}} \ |
| 605 |
// expected-note@-1 {{'DerivedClass' is not standard-layout}} \ |
| 606 |
// expected-note@-1 {{because it has multiple base classes with data members}} \ |
| 607 |
// expected-note@#sl-DerivedClass {{'DerivedClass' defined here}} |
| 608 |
|
| 609 |
// Inheritance hierarchy with multiple classes having data members |
| 610 |
struct BaseA { int a; }; // #sl-BaseA |
| 611 |
struct BaseB : BaseA {}; // inherits BaseA, has no new members |
| 612 |
struct BaseC: BaseB { int c; }; // #sl-BaseC |
| 613 |
static_assert(__is_standard_layout(BaseC)); |
| 614 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::BaseC)'}} \ |
| 615 |
// expected-note@-1 {{'BaseC' is not standard-layout}} \ |
| 616 |
// expected-note@-1 {{because it has an indirect base 'BaseA' with data members}} \ |
| 617 |
// expected-note@#sl-BaseC {{'BaseC' defined here}} \ |
| 618 |
// Multiple direct base classes with no data members --> standard layout |
| 619 |
struct BaseX {}; // #sl-BaseX |
| 620 |
struct BaseY {}; // #sl-BaseY |
| 621 |
struct MultiBase : BaseX, BaseY {}; // #sl-MultiBase |
| 622 |
static_assert(__is_standard_layout(MultiBase)); |
| 623 |
|
| 624 |
struct A { |
| 625 |
int x; |
| 626 |
}; |
| 627 |
|
| 628 |
struct B : A { |
| 629 |
}; |
| 630 |
// Indirect base with data members |
| 631 |
struct C : B { int y; }; // #sl-C |
| 632 |
static_assert(__is_standard_layout(C)); |
| 633 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::C)'}} \ |
| 634 |
// expected-note@-1 {{'C' is not standard-layout}} \ |
| 635 |
// expected-note@-1 {{because it has an indirect base 'A' with data members}} \ |
| 636 |
// expected-note@#sl-C {{'C' defined here}} |
| 637 |
|
| 638 |
struct D { |
| 639 |
union { int a; float b; }; |
| 640 |
}; // #sl-D |
| 641 |
static_assert(__is_standard_layout(D)); // no diagnostics |
| 642 |
|
| 643 |
// E inherits D but adds a new member |
| 644 |
struct E : D { int x; }; // #sl-E |
| 645 |
static_assert(__is_standard_layout(E)); |
| 646 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::E)'}} \ |
| 647 |
// expected-note@-1 {{'E' is not standard-layout}} \ |
| 648 |
// expected-note@-1 {{because it has an indirect base 'D' with data members}} \ |
| 649 |
// expected-note@#sl-E {{'E' defined here}} |
| 650 |
|
| 651 |
// F inherits D but only an unnamed bitfield |
| 652 |
// This should still fail because F ends up with a |
| 653 |
// base class with a data member and its own unnamed bitfield |
| 654 |
// which is not allowed in standard layout |
| 655 |
struct F : D { int : 0; }; // #sl-F |
| 656 |
static_assert(__is_standard_layout(F)); |
| 657 |
// expected-error@-1 {{static assertion failed due to requirement '__is_standard_layout(standard_layout_tests::F)'}} \ |
| 658 |
// expected-note@-1 {{'F' is not standard-layout}} \ |
| 659 |
// expected-note@#sl-F {{'F' defined here}} |
| 660 |
|
| 661 |
struct Empty {}; |
| 662 |
struct G { Empty a, b; }; // #sl-G |
| 663 |
static_assert(__is_standard_layout(G)); // no diagnostics |
| 664 |
|
| 665 |
struct H { Empty a; int x; }; // #sl-H |
| 666 |
static_assert(__is_standard_layout(H)); // no diagnostics |
| 667 |
|
| 668 |
struct I { Empty a; int : 0; int x; }; // #sl-I |
| 669 |
static_assert(__is_standard_layout(I)); // no diagnostics |
| 670 |
} |
| 671 |
|
| 672 |
namespace is_final_tests { |
| 673 |
struct C {}; // #e-C |
| 674 |
static_assert(__is_final(C)); |
| 675 |
// expected-error@-1 {{static assertion failed due to requirement '__is_final(is_final_tests::C)'}} \ |
| 676 |
// expected-note@-1 {{'C' is not final}} \ |
| 677 |
// expected-note@-1 {{because it is not marked 'final'}} \ |
| 678 |
// expected-note@#e-C {{'C' defined here}} |
| 679 |
|
| 680 |
union U {}; // #e-U |
| 681 |
static_assert(__is_final(U)); |
| 682 |
// expected-error@-1 {{static assertion failed due to requirement '__is_final(is_final_tests::U)'}} \ |
| 683 |
// expected-note@-1 {{'U' is not final}} \ |
| 684 |
// expected-note@-1 {{because it is not marked 'final'}} \ |
| 685 |
// expected-note@#e-U {{'U' defined here}} |
| 686 |
|
| 687 |
// ----- non-class/union types ----- |
| 688 |
using I = int; |
| 689 |
static_assert(__is_final(I)); |
| 690 |
// expected-error@-1 {{static assertion failed due to requirement '__is_final(int)'}} \ |
| 691 |
// expected-note@-1 {{'I' (aka 'int') is not final}} \ |
| 692 |
// expected-note@-1 {{because it is not a class or union type}} |
| 693 |
|
| 694 |
using Fty = void(); // function type |
| 695 |
static_assert(__is_final(Fty)); |
| 696 |
// expected-error@-1 {{static assertion failed due to requirement '__is_final(void ())'}} \ |
| 697 |
// expected-note@-1 {{'Fty' (aka 'void ()') is not final}} \ |
| 698 |
// expected-note@-1 {{because it is a function type}} \ |
| 699 |
// expected-note@-1 {{because it is not a class or union type}} |
| 700 |
|
| 701 |
using Arr = int[3]; |
| 702 |
static_assert(__is_final(Arr)); |
| 703 |
// expected-error@-1 {{static assertion failed due to requirement '__is_final(int[3])'}} \ |
| 704 |
// expected-note@-1 {{'Arr' (aka 'int[3]') is not final}} \ |
| 705 |
// expected-note@-1 {{because it is not a class or union type}} |
| 706 |
|
| 707 |
using Ref = int&; |
| 708 |
static_assert(__is_final(Ref)); |
| 709 |
// expected-error@-1 {{static assertion failed due to requirement '__is_final(int &)'}} \ |
| 710 |
// expected-note@-1 {{'Ref' (aka 'int &') is not final}} \ |
| 711 |
// expected-note@-1 {{because it is a reference type}} \ |
| 712 |
// expected-note@-1 {{because it is not a class or union type}} |
| 713 |
|
| 714 |
} |
| 715 |
namespace is_aggregate { |
| 716 |
struct S1 { // #ag-S1 |
| 717 |
S1(int); |
| 718 |
}; |
| 719 |
|
| 720 |
static_assert(__is_aggregate(S1)); |
| 721 |
// expected-error@-1 {{static assertion failed due to requirement '__is_aggregate(is_aggregate::S1)'}} \ |
| 722 |
// expected-note@-1 {{because it has a user-declared constructor}} \ |
| 723 |
// expected-note@-1 {{'S1' is not aggregate}} \ |
| 724 |
// expected-note@#ag-S1 {{'S1' defined here}} |
| 725 |
|
| 726 |
struct B2 { |
| 727 |
B2(int); |
| 728 |
}; |
| 729 |
|
| 730 |
struct S2 : B2 { // #ag-S2 |
| 731 |
using B2::B2; |
| 732 |
}; |
| 733 |
|
| 734 |
static_assert(__is_aggregate(S2)); |
| 735 |
// expected-error@-1 {{static assertion failed due to requirement '__is_aggregate(is_aggregate::S2)'}} \ |
| 736 |
// expected-note@-1 {{because it has an inherited constructor}} \ |
| 737 |
// expected-note@-1 {{'S2' is not aggregate}} \ |
| 738 |
// expected-note@#ag-S2 {{'S2' defined here}} |
| 739 |
|
| 740 |
struct S3 { // #ag-S3 |
| 741 |
protected: |
| 742 |
int x; |
| 743 |
}; |
| 744 |
static_assert(__is_aggregate(S3)); |
| 745 |
// expected-error@-1 {{static assertion failed due to requirement '__is_aggregate(is_aggregate::S3)'}} \ |
| 746 |
// expected-note@-1 {{because it has a protected direct data member}} \ |
| 747 |
// expected-note@-1 {{'S3' is not aggregate}} \ |
| 748 |
// expected-note@#ag-S3 {{'S3' defined here}} |
| 749 |
|
| 750 |
struct S4 { // #ag-S4 |
| 751 |
private: |
| 752 |
int x; |
| 753 |
}; |
| 754 |
static_assert(__is_aggregate(S4)); |
| 755 |
// expected-error@-1 {{static assertion failed due to requirement '__is_aggregate(is_aggregate::S4)'}} \ |
| 756 |
// expected-note@-1 {{because it has a private direct data member}} \ |
| 757 |
// expected-note@-1 {{'S4' is not aggregate}} \ |
| 758 |
// expected-note@#ag-S4 {{'S4' defined here}} |
| 759 |
|
| 760 |
struct B5 {}; |
| 761 |
|
| 762 |
struct S5 : private B5 { // #ag-S5 |
| 763 |
private: |
| 764 |
int x; |
| 765 |
}; |
| 766 |
static_assert(__is_aggregate(S5)); |
| 767 |
// expected-error@-1 {{static assertion failed due to requirement '__is_aggregate(is_aggregate::S5)'}} \ |
| 768 |
// expected-note@-1 {{because it has a private direct base}} \ |
| 769 |
// expected-note@-1 {{because it has a private direct data member}} \ |
| 770 |
// expected-note@-1 {{'S5' is not aggregate}} \ |
| 771 |
// expected-note@#ag-S5 {{'S5' defined here}} |
| 772 |
|
| 773 |
struct B6 {}; |
| 774 |
|
| 775 |
struct S6 : protected B6 { // #ag-S6 |
| 776 |
private: |
| 777 |
int x; |
| 778 |
}; |
| 779 |
static_assert(__is_aggregate(S6)); |
| 780 |
// expected-error@-1 {{static assertion failed due to requirement '__is_aggregate(is_aggregate::S6)'}} \ |
| 781 |
// expected-note@-1 {{because it has a protected direct base}} \ |
| 782 |
// expected-note@-1 {{because it has a private direct data member}} \ |
| 783 |
// expected-note@-1 {{'S6' is not aggregate}} \ |
| 784 |
// expected-note@#ag-S6 {{'S6' defined here}} |
| 785 |
|
| 786 |
static_assert(__is_aggregate(S6[])); |
| 787 |
|
| 788 |
struct B7 {}; |
| 789 |
|
| 790 |
struct S7 : virtual B7 { // #ag-S7 |
| 791 |
virtual void foo(); |
| 792 |
|
| 793 |
private: |
| 794 |
int x; |
| 795 |
}; |
| 796 |
static_assert(__is_aggregate(S7)); |
| 797 |
// expected-error@-1 {{static assertion failed due to requirement '__is_aggregate(is_aggregate::S7)'}} \ |
| 798 |
// expected-note@-1 {{because it has a private direct data member}} \ |
| 799 |
// expected-note@-1 {{because it has a virtual function 'foo'}} \ |
| 800 |
// expected-note@-1 {{because it has a virtual base}} \ |
| 801 |
// expected-note@-1 {{'S7' is not aggregate}} \ |
| 802 |
// expected-note@-1 {{because it is a polymorphic type}} \ |
| 803 |
// expected-note@#ag-S7 {{'S7' defined here}} |
| 804 |
|
| 805 |
static_assert(__is_aggregate(S7[10])); |
| 806 |
} |
| 807 |
|
| 808 |
namespace is_abstract_tests { |
| 809 |
struct Abstract1 { |
| 810 |
virtual void fn1() = 0; |
| 811 |
}; |
| 812 |
|
| 813 |
struct Abstract2 { |
| 814 |
virtual void fn2() = 0; |
| 815 |
}; |
| 816 |
|
| 817 |
struct NonAbstract |
| 818 |
{ |
| 819 |
virtual void f() {} |
| 820 |
}; |
| 821 |
|
| 822 |
// Multiple inheritance reports all abstract base classes that had their pure virtual functions overridden. |
| 823 |
struct Overrides : Abstract1, Abstract2, NonAbstract { |
| 824 |
void fn1() override {} |
| 825 |
void fn2() override {} |
| 826 |
}; |
| 827 |
|
| 828 |
static_assert(__is_abstract(Overrides)); |
| 829 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(is_abstract_tests::Overrides)'}} \ |
| 830 |
// expected-note@-1 {{'Overrides' is not abstract}} \ |
| 831 |
// expected-note@-1 {{because it overrides all pure virtual functions from base class 'Abstract1'}} \ |
| 832 |
// expected-note@-1 {{because it overrides all pure virtual functions from base class 'Abstract2'}} \ |
| 833 |
|
| 834 |
static_assert(__is_abstract(NonAbstract)); |
| 835 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(is_abstract_tests::NonAbstract)'}} \ |
| 836 |
// expected-note@-1 {{'NonAbstract' is not abstract}} |
| 837 |
|
| 838 |
// Inheriting over two levels reports the last class only although the source of the pure virtual function |
| 839 |
// is the top-most base. |
| 840 |
struct Derived : Abstract1 { |
| 841 |
}; |
| 842 |
|
| 843 |
struct Derived2 : Derived { |
| 844 |
void fn1() override {} |
| 845 |
}; |
| 846 |
|
| 847 |
static_assert(__is_abstract(Derived2)); |
| 848 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(is_abstract_tests::Derived2)'}} \ |
| 849 |
// expected-note@-1 {{'Derived2' is not abstract}} \ |
| 850 |
// expected-note@-1 {{because it overrides all pure virtual functions from base class 'Derived'}} \ |
| 851 |
|
| 852 |
|
| 853 |
using I = int; |
| 854 |
static_assert(__is_abstract(I)); |
| 855 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(int)'}} \ |
| 856 |
// expected-note@-1 {{'I' (aka 'int') is not abstract}} \ |
| 857 |
// expected-note@-1 {{because it is not a struct or class type}} |
| 858 |
|
| 859 |
using Fty = void(); |
| 860 |
static_assert(__is_abstract(Fty)); |
| 861 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(void ())'}} \ |
| 862 |
// expected-note@-1 {{'Fty' (aka 'void ()') is not abstract}} \ |
| 863 |
// expected-note@-1 {{because it is a function type}} \ |
| 864 |
// expected-note@-1 {{because it is not a struct or class type}} |
| 865 |
|
| 866 |
using Arr = int[3]; |
| 867 |
static_assert(__is_abstract(Arr)); |
| 868 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(int[3])'}} \ |
| 869 |
// expected-note@-1 {{'Arr' (aka 'int[3]') is not abstract}} \ |
| 870 |
// expected-note@-1 {{because it is an array type}} \ |
| 871 |
// expected-note@-1 {{because it is not a struct or class type}} |
| 872 |
|
| 873 |
using Ref = int&; |
| 874 |
static_assert(__is_abstract(Ref)); |
| 875 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(int &)'}} \ |
| 876 |
// expected-note@-1 {{'Ref' (aka 'int &') is not abstract}} \ |
| 877 |
// expected-note@-1 {{because it is a reference type}} \ |
| 878 |
// expected-note@-1 {{because it is not a struct or class type}} |
| 879 |
|
| 880 |
using Ptr = int*; |
| 881 |
static_assert(__is_abstract(Ptr)); |
| 882 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(int *)'}} \ |
| 883 |
// expected-note@-1 {{'Ptr' (aka 'int *') is not abstract}} \ |
| 884 |
// expected-note@-1 {{because it is a pointer type}} \ |
| 885 |
// expected-note@-1 {{because it is not a struct or class type}} |
| 886 |
|
| 887 |
union U { int x; float y;}; |
| 888 |
static_assert(__is_abstract(U)); |
| 889 |
// expected-error@-1 {{static assertion failed due to requirement '__is_abstract(is_abstract_tests::U)'}} \ |
| 890 |
// expected-note@-1 {{'U' is not abstract}} \ |
| 891 |
// expected-note@-1 {{because it is a union type}} \ |
| 892 |
// expected-note@-1 {{because it is not a struct or class type}} |
| 893 |
|
| 894 |
} |