| 1 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++11 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted -Wno-c++17-extensions %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++14 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted -Wno-c++17-extensions %s |
| 3 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++17 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s |
| 4 |
// RUN: %clang_cc1 -triple x86_64-apple-darwin10 -fsyntax-only -verify -std=gnu++20 -fblocks -Wno-deprecated-builtins -Wno-defaulted-function-deleted %s |
| 5 |
|
| 6 |
|
| 7 |
struct NonPOD { NonPOD(int); }; |
| 8 |
typedef NonPOD NonPODAr[10]; |
| 9 |
typedef NonPOD NonPODArNB[]; |
| 10 |
typedef NonPOD NonPODArMB[10][2]; |
| 11 |
|
| 12 |
// PODs |
| 13 |
enum Enum { EV }; |
| 14 |
enum SignedEnum : signed int { }; |
| 15 |
enum UnsignedEnum : unsigned int { }; |
| 16 |
enum class EnumClass { EV }; |
| 17 |
enum class SignedEnumClass : signed int {}; |
| 18 |
enum class UnsignedEnumClass : unsigned int {}; |
| 19 |
struct POD { Enum e; int i; float f; NonPOD* p; }; |
| 20 |
struct Empty {}; |
| 21 |
struct IncompleteStruct; // expected-note {{forward declaration of 'IncompleteStruct'}} |
| 22 |
typedef Empty EmptyAr[10]; |
| 23 |
typedef Empty EmptyArNB[]; |
| 24 |
typedef Empty EmptyArMB[1][2]; |
| 25 |
typedef int Int; |
| 26 |
typedef Int IntAr[10]; |
| 27 |
typedef Int IntArNB[]; |
| 28 |
typedef Int IntArZero[0]; |
| 29 |
class Statics { static int priv; static NonPOD np; }; |
| 30 |
union EmptyUnion {}; |
| 31 |
union IncompleteUnion; // expected-note {{forward declaration of 'IncompleteUnion'}} |
| 32 |
union Union { int i; float f; }; |
| 33 |
struct HasFunc { void f (); }; |
| 34 |
struct HasOp { void operator *(); }; |
| 35 |
struct HasConv { operator int(); }; |
| 36 |
struct HasAssign { void operator =(int); }; |
| 37 |
|
| 38 |
struct HasAnonymousUnion { |
| 39 |
union { |
| 40 |
int i; |
| 41 |
float f; |
| 42 |
}; |
| 43 |
}; |
| 44 |
|
| 45 |
typedef int Vector __attribute__((vector_size(16))); |
| 46 |
typedef int VectorExt __attribute__((ext_vector_type(4))); |
| 47 |
|
| 48 |
using ComplexFloat = _Complex float; |
| 49 |
using ComplexInt = _Complex int; |
| 50 |
|
| 51 |
// Not PODs |
| 52 |
typedef const void cvoid; |
| 53 |
struct Derives : POD {}; |
| 54 |
typedef Derives DerivesAr[10]; |
| 55 |
typedef Derives DerivesArNB[]; |
| 56 |
struct DerivesEmpty : Empty {}; |
| 57 |
struct HasCons { HasCons(int); }; |
| 58 |
struct HasDefaultCons { HasDefaultCons() = default; }; |
| 59 |
struct HasExplicitDefaultCons { explicit HasExplicitDefaultCons() = default; }; |
| 60 |
struct HasInheritedCons : HasDefaultCons { using HasDefaultCons::HasDefaultCons; }; |
| 61 |
struct HasNoInheritedCons : HasCons {}; |
| 62 |
struct HasCopyAssign { HasCopyAssign operator =(const HasCopyAssign&); }; |
| 63 |
struct HasMoveAssign { HasMoveAssign operator =(const HasMoveAssign&&); }; |
| 64 |
struct HasNoThrowMoveAssign { |
| 65 |
HasNoThrowMoveAssign& operator=( |
| 66 |
const HasNoThrowMoveAssign&&) throw(); }; |
| 67 |
struct HasNoExceptNoThrowMoveAssign { |
| 68 |
HasNoExceptNoThrowMoveAssign& operator=( |
| 69 |
const HasNoExceptNoThrowMoveAssign&&) noexcept; |
| 70 |
}; |
| 71 |
struct HasThrowMoveAssign { |
| 72 |
HasThrowMoveAssign& operator=(const HasThrowMoveAssign&&) |
| 73 |
#if __cplusplus <= 201402L |
| 74 |
throw(POD); |
| 75 |
#else |
| 76 |
noexcept(false); |
| 77 |
#endif |
| 78 |
}; |
| 79 |
|
| 80 |
|
| 81 |
struct HasNoExceptFalseMoveAssign { |
| 82 |
HasNoExceptFalseMoveAssign& operator=( |
| 83 |
const HasNoExceptFalseMoveAssign&&) noexcept(false); }; |
| 84 |
struct HasMoveCtor { HasMoveCtor(const HasMoveCtor&&); }; |
| 85 |
struct HasMemberMoveCtor { HasMoveCtor member; }; |
| 86 |
struct HasMemberMoveAssign { HasMoveAssign member; }; |
| 87 |
struct HasStaticMemberMoveCtor { static HasMoveCtor member; }; |
| 88 |
struct HasStaticMemberMoveAssign { static HasMoveAssign member; }; |
| 89 |
struct HasMemberThrowMoveAssign { HasThrowMoveAssign member; }; |
| 90 |
struct HasMemberNoExceptFalseMoveAssign { |
| 91 |
HasNoExceptFalseMoveAssign member; }; |
| 92 |
struct HasMemberNoThrowMoveAssign { HasNoThrowMoveAssign member; }; |
| 93 |
struct HasMemberNoExceptNoThrowMoveAssign { |
| 94 |
HasNoExceptNoThrowMoveAssign member; }; |
| 95 |
|
| 96 |
struct HasDefaultTrivialCopyAssign { |
| 97 |
HasDefaultTrivialCopyAssign &operator=( |
| 98 |
const HasDefaultTrivialCopyAssign&) = default; |
| 99 |
}; |
| 100 |
struct TrivialMoveButNotCopy { |
| 101 |
TrivialMoveButNotCopy &operator=(TrivialMoveButNotCopy&&) = default; |
| 102 |
TrivialMoveButNotCopy &operator=(const TrivialMoveButNotCopy&); |
| 103 |
}; |
| 104 |
struct NonTrivialDefault { |
| 105 |
NonTrivialDefault(); |
| 106 |
}; |
| 107 |
|
| 108 |
struct HasDest { ~HasDest(); }; |
| 109 |
class HasPriv { int priv; }; |
| 110 |
class HasProt { protected: int prot; }; |
| 111 |
struct HasRef { int i; int& ref; HasRef() : i(0), ref(i) {} }; |
| 112 |
struct HasRefAggregate { int i; int& ref; }; |
| 113 |
struct HasNonPOD { NonPOD np; }; |
| 114 |
struct HasVirt { virtual void Virt() {}; }; |
| 115 |
typedef NonPOD NonPODAr[10]; |
| 116 |
typedef HasVirt VirtAr[10]; |
| 117 |
typedef NonPOD NonPODArNB[]; |
| 118 |
union NonPODUnion { int i; Derives n; }; |
| 119 |
struct DerivesHasCons : HasCons {}; |
| 120 |
struct DerivesHasCopyAssign : HasCopyAssign {}; |
| 121 |
struct DerivesHasMoveAssign : HasMoveAssign {}; |
| 122 |
struct DerivesHasDest : HasDest {}; |
| 123 |
struct DerivesHasPriv : HasPriv {}; |
| 124 |
struct DerivesHasProt : HasProt {}; |
| 125 |
struct DerivesHasRef : HasRef {}; |
| 126 |
struct DerivesHasVirt : HasVirt {}; |
| 127 |
struct DerivesHasMoveCtor : HasMoveCtor {}; |
| 128 |
|
| 129 |
struct HasNoThrowCopyAssign { |
| 130 |
void operator =(const HasNoThrowCopyAssign&) throw(); |
| 131 |
}; |
| 132 |
struct HasMultipleCopyAssign { |
| 133 |
void operator =(const HasMultipleCopyAssign&) throw(); |
| 134 |
void operator =(volatile HasMultipleCopyAssign&); |
| 135 |
}; |
| 136 |
struct HasMultipleNoThrowCopyAssign { |
| 137 |
void operator =(const HasMultipleNoThrowCopyAssign&) throw(); |
| 138 |
void operator =(volatile HasMultipleNoThrowCopyAssign&) throw(); |
| 139 |
}; |
| 140 |
|
| 141 |
struct HasNoThrowConstructor { HasNoThrowConstructor() throw(); }; |
| 142 |
struct HasNoThrowConstructorWithArgs { |
| 143 |
HasNoThrowConstructorWithArgs(HasCons i = HasCons(0)) throw(); |
| 144 |
}; |
| 145 |
struct HasMultipleDefaultConstructor1 { |
| 146 |
HasMultipleDefaultConstructor1() throw(); |
| 147 |
HasMultipleDefaultConstructor1(int i = 0); |
| 148 |
}; |
| 149 |
struct HasMultipleDefaultConstructor2 { |
| 150 |
HasMultipleDefaultConstructor2(int i = 0); |
| 151 |
HasMultipleDefaultConstructor2() throw(); |
| 152 |
}; |
| 153 |
|
| 154 |
struct HasNoThrowCopy { HasNoThrowCopy(const HasNoThrowCopy&) throw(); }; |
| 155 |
struct HasMultipleCopy { |
| 156 |
HasMultipleCopy(const HasMultipleCopy&) throw(); |
| 157 |
HasMultipleCopy(volatile HasMultipleCopy&); |
| 158 |
}; |
| 159 |
struct HasMultipleNoThrowCopy { |
| 160 |
HasMultipleNoThrowCopy(const HasMultipleNoThrowCopy&) throw(); |
| 161 |
HasMultipleNoThrowCopy(volatile HasMultipleNoThrowCopy&) throw(); |
| 162 |
}; |
| 163 |
|
| 164 |
struct HasVirtDest { virtual ~HasVirtDest(); }; |
| 165 |
struct DerivedVirtDest : HasVirtDest {}; |
| 166 |
typedef HasVirtDest VirtDestAr[1]; |
| 167 |
|
| 168 |
class AllPrivate { |
| 169 |
AllPrivate() throw(); |
| 170 |
AllPrivate(const AllPrivate&) throw(); |
| 171 |
AllPrivate &operator=(const AllPrivate &) throw(); |
| 172 |
~AllPrivate() throw(); |
| 173 |
}; |
| 174 |
|
| 175 |
struct ThreeArgCtor { |
| 176 |
ThreeArgCtor(int*, char*, int); |
| 177 |
}; |
| 178 |
|
| 179 |
struct VariadicCtor { |
| 180 |
template<typename...T> VariadicCtor(T...); |
| 181 |
}; |
| 182 |
|
| 183 |
struct ThrowingDtor { |
| 184 |
~ThrowingDtor() |
| 185 |
#if __cplusplus <= 201402L |
| 186 |
throw(int); |
| 187 |
#else |
| 188 |
noexcept(false); |
| 189 |
#endif |
| 190 |
}; |
| 191 |
|
| 192 |
struct NoExceptDtor { |
| 193 |
~NoExceptDtor() noexcept(true); |
| 194 |
}; |
| 195 |
|
| 196 |
struct NoThrowDtor { |
| 197 |
~NoThrowDtor() throw(); |
| 198 |
}; |
| 199 |
|
| 200 |
struct ACompleteType {}; |
| 201 |
struct AnIncompleteType; // expected-note 1+ {{forward declaration of 'AnIncompleteType'}} |
| 202 |
typedef AnIncompleteType AnIncompleteTypeAr[42]; |
| 203 |
typedef AnIncompleteType AnIncompleteTypeArNB[]; |
| 204 |
typedef AnIncompleteType AnIncompleteTypeArMB[1][10]; |
| 205 |
|
| 206 |
struct HasInClassInit { |
| 207 |
int x = 42; |
| 208 |
}; |
| 209 |
|
| 210 |
struct HasPrivateBase : private ACompleteType {}; |
| 211 |
struct HasProtectedBase : protected ACompleteType {}; |
| 212 |
struct HasVirtBase : virtual ACompleteType {}; |
| 213 |
|
| 214 |
void is_pod() |
| 215 |
{ |
| 216 |
static_assert(__is_pod(int)); |
| 217 |
static_assert(__is_pod(Enum)); |
| 218 |
static_assert(__is_pod(POD)); |
| 219 |
static_assert(__is_pod(Int)); |
| 220 |
static_assert(__is_pod(IntAr)); |
| 221 |
static_assert(__is_pod(Statics)); |
| 222 |
static_assert(__is_pod(Empty)); |
| 223 |
static_assert(__is_pod(EmptyUnion)); |
| 224 |
static_assert(__is_pod(Union)); |
| 225 |
static_assert(__is_pod(HasFunc)); |
| 226 |
static_assert(__is_pod(HasOp)); |
| 227 |
static_assert(__is_pod(HasConv)); |
| 228 |
static_assert(__is_pod(HasAssign)); |
| 229 |
static_assert(__is_pod(IntArNB)); |
| 230 |
static_assert(__is_pod(HasAnonymousUnion)); |
| 231 |
static_assert(__is_pod(Vector)); |
| 232 |
static_assert(__is_pod(VectorExt)); |
| 233 |
static_assert(__is_pod(Derives)); |
| 234 |
static_assert(__is_pod(DerivesAr)); |
| 235 |
static_assert(__is_pod(DerivesArNB)); |
| 236 |
static_assert(__is_pod(DerivesEmpty)); |
| 237 |
static_assert(__is_pod(HasPriv)); |
| 238 |
static_assert(__is_pod(HasProt)); |
| 239 |
static_assert(__is_pod(DerivesHasPriv)); |
| 240 |
static_assert(__is_pod(DerivesHasProt)); |
| 241 |
|
| 242 |
static_assert(!__is_pod(HasCons)); |
| 243 |
static_assert(!__is_pod(HasCopyAssign)); |
| 244 |
static_assert(!__is_pod(HasMoveAssign)); |
| 245 |
static_assert(!__is_pod(HasDest)); |
| 246 |
static_assert(!__is_pod(HasRef)); |
| 247 |
static_assert(!__is_pod(HasVirt)); |
| 248 |
static_assert(!__is_pod(DerivesHasCons)); |
| 249 |
static_assert(!__is_pod(DerivesHasCopyAssign)); |
| 250 |
static_assert(!__is_pod(DerivesHasMoveAssign)); |
| 251 |
static_assert(!__is_pod(DerivesHasDest)); |
| 252 |
static_assert(!__is_pod(DerivesHasRef)); |
| 253 |
static_assert(!__is_pod(DerivesHasVirt)); |
| 254 |
static_assert(!__is_pod(NonPOD)); |
| 255 |
static_assert(!__is_pod(HasNonPOD)); |
| 256 |
static_assert(!__is_pod(NonPODAr)); |
| 257 |
static_assert(!__is_pod(NonPODArNB)); |
| 258 |
static_assert(!__is_pod(void)); |
| 259 |
static_assert(!__is_pod(cvoid)); |
| 260 |
// static_assert(!__is_pod(NonPODUnion)); |
| 261 |
|
| 262 |
static_assert(__is_pod(ACompleteType)); |
| 263 |
static_assert(!__is_pod(AnIncompleteType)); // expected-error {{incomplete type}} |
| 264 |
static_assert(!__is_pod(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 265 |
static_assert(!__is_pod(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 266 |
} |
| 267 |
|
| 268 |
typedef Empty EmptyAr[10]; |
| 269 |
struct Bit0 { int : 0; }; |
| 270 |
struct Bit0Cons { int : 0; Bit0Cons(); }; |
| 271 |
struct AnonBitOnly { int : 3; }; |
| 272 |
struct BitOnly { int x : 3; }; |
| 273 |
struct DerivesVirt : virtual POD {}; |
| 274 |
|
| 275 |
void is_empty() |
| 276 |
{ |
| 277 |
static_assert(__is_empty(Empty)); |
| 278 |
static_assert(__is_empty(DerivesEmpty)); |
| 279 |
static_assert(__is_empty(HasCons)); |
| 280 |
static_assert(__is_empty(HasCopyAssign)); |
| 281 |
static_assert(__is_empty(HasMoveAssign)); |
| 282 |
static_assert(__is_empty(HasDest)); |
| 283 |
static_assert(__is_empty(HasFunc)); |
| 284 |
static_assert(__is_empty(HasOp)); |
| 285 |
static_assert(__is_empty(HasConv)); |
| 286 |
static_assert(__is_empty(HasAssign)); |
| 287 |
static_assert(__is_empty(Bit0)); |
| 288 |
static_assert(__is_empty(Bit0Cons)); |
| 289 |
|
| 290 |
static_assert(!__is_empty(Int)); |
| 291 |
static_assert(!__is_empty(POD)); |
| 292 |
static_assert(!__is_empty(EmptyUnion)); |
| 293 |
static_assert(!__is_empty(IncompleteUnion)); |
| 294 |
static_assert(!__is_empty(EmptyAr)); |
| 295 |
static_assert(!__is_empty(HasRef)); |
| 296 |
static_assert(!__is_empty(HasVirt)); |
| 297 |
static_assert(!__is_empty(AnonBitOnly)); |
| 298 |
static_assert(!__is_empty(BitOnly)); |
| 299 |
static_assert(!__is_empty(void)); |
| 300 |
static_assert(!__is_empty(IntArNB)); |
| 301 |
static_assert(!__is_empty(HasAnonymousUnion)); |
| 302 |
// static_assert(!__is_empty(DerivesVirt)); |
| 303 |
|
| 304 |
static_assert(__is_empty(ACompleteType)); |
| 305 |
static_assert(!__is_empty(AnIncompleteType)); // expected-error {{incomplete type}} |
| 306 |
static_assert(!__is_empty(AnIncompleteType[])); |
| 307 |
static_assert(!__is_empty(AnIncompleteType[1])); |
| 308 |
} |
| 309 |
|
| 310 |
typedef Derives ClassType; |
| 311 |
|
| 312 |
void is_class() |
| 313 |
{ |
| 314 |
static_assert(__is_class(Derives)); |
| 315 |
static_assert(__is_class(HasPriv)); |
| 316 |
static_assert(__is_class(ClassType)); |
| 317 |
static_assert(__is_class(HasAnonymousUnion)); |
| 318 |
|
| 319 |
static_assert(!__is_class(int)); |
| 320 |
static_assert(!__is_class(Enum)); |
| 321 |
static_assert(!__is_class(Int)); |
| 322 |
static_assert(!__is_class(IntAr)); |
| 323 |
static_assert(!__is_class(DerivesAr)); |
| 324 |
static_assert(!__is_class(Union)); |
| 325 |
static_assert(!__is_class(cvoid)); |
| 326 |
static_assert(!__is_class(IntArNB)); |
| 327 |
} |
| 328 |
|
| 329 |
typedef Union UnionAr[10]; |
| 330 |
typedef Union UnionType; |
| 331 |
|
| 332 |
void is_union() |
| 333 |
{ |
| 334 |
static_assert(__is_union(Union)); |
| 335 |
static_assert(__is_union(UnionType)); |
| 336 |
|
| 337 |
static_assert(!__is_union(int)); |
| 338 |
static_assert(!__is_union(Enum)); |
| 339 |
static_assert(!__is_union(Int)); |
| 340 |
static_assert(!__is_union(IntAr)); |
| 341 |
static_assert(!__is_union(UnionAr)); |
| 342 |
static_assert(!__is_union(cvoid)); |
| 343 |
static_assert(!__is_union(IntArNB)); |
| 344 |
static_assert(!__is_union(HasAnonymousUnion)); |
| 345 |
} |
| 346 |
|
| 347 |
typedef Enum EnumType; |
| 348 |
typedef EnumClass EnumClassType; |
| 349 |
|
| 350 |
void is_enum() |
| 351 |
{ |
| 352 |
static_assert(__is_enum(Enum)); |
| 353 |
static_assert(__is_enum(EnumType)); |
| 354 |
static_assert(__is_enum(SignedEnum)); |
| 355 |
static_assert(__is_enum(UnsignedEnum)); |
| 356 |
|
| 357 |
static_assert(__is_enum(EnumClass)); |
| 358 |
static_assert(__is_enum(EnumClassType)); |
| 359 |
static_assert(__is_enum(SignedEnumClass)); |
| 360 |
static_assert(__is_enum(UnsignedEnumClass)); |
| 361 |
|
| 362 |
static_assert(!__is_enum(int)); |
| 363 |
static_assert(!__is_enum(Union)); |
| 364 |
static_assert(!__is_enum(Int)); |
| 365 |
static_assert(!__is_enum(IntAr)); |
| 366 |
static_assert(!__is_enum(UnionAr)); |
| 367 |
static_assert(!__is_enum(Derives)); |
| 368 |
static_assert(!__is_enum(ClassType)); |
| 369 |
static_assert(!__is_enum(cvoid)); |
| 370 |
static_assert(!__is_enum(IntArNB)); |
| 371 |
static_assert(!__is_enum(HasAnonymousUnion)); |
| 372 |
static_assert(!__is_enum(AnIncompleteType)); |
| 373 |
static_assert(!__is_enum(AnIncompleteTypeAr)); |
| 374 |
static_assert(!__is_enum(AnIncompleteTypeArMB)); |
| 375 |
static_assert(!__is_enum(AnIncompleteTypeArNB)); |
| 376 |
} |
| 377 |
|
| 378 |
void is_scoped_enum() { |
| 379 |
static_assert(!__is_scoped_enum(Enum)); |
| 380 |
static_assert(!__is_scoped_enum(EnumType)); |
| 381 |
static_assert(!__is_scoped_enum(SignedEnum)); |
| 382 |
static_assert(!__is_scoped_enum(UnsignedEnum)); |
| 383 |
|
| 384 |
static_assert(__is_scoped_enum(EnumClass)); |
| 385 |
static_assert(__is_scoped_enum(EnumClassType)); |
| 386 |
static_assert(__is_scoped_enum(SignedEnumClass)); |
| 387 |
static_assert(__is_scoped_enum(UnsignedEnumClass)); |
| 388 |
|
| 389 |
static_assert(!__is_scoped_enum(int)); |
| 390 |
static_assert(!__is_scoped_enum(Union)); |
| 391 |
static_assert(!__is_scoped_enum(Int)); |
| 392 |
static_assert(!__is_scoped_enum(IntAr)); |
| 393 |
static_assert(!__is_scoped_enum(UnionAr)); |
| 394 |
static_assert(!__is_scoped_enum(Derives)); |
| 395 |
static_assert(!__is_scoped_enum(ClassType)); |
| 396 |
static_assert(!__is_scoped_enum(cvoid)); |
| 397 |
static_assert(!__is_scoped_enum(IntArNB)); |
| 398 |
static_assert(!__is_scoped_enum(HasAnonymousUnion)); |
| 399 |
static_assert(!__is_scoped_enum(AnIncompleteType)); |
| 400 |
static_assert(!__is_scoped_enum(AnIncompleteTypeAr)); |
| 401 |
static_assert(!__is_scoped_enum(AnIncompleteTypeArMB)); |
| 402 |
static_assert(!__is_scoped_enum(AnIncompleteTypeArNB)); |
| 403 |
} |
| 404 |
|
| 405 |
struct FinalClass final { |
| 406 |
}; |
| 407 |
|
| 408 |
template<typename T> |
| 409 |
struct PotentiallyFinal { }; |
| 410 |
|
| 411 |
template<typename T> |
| 412 |
struct PotentiallyFinal<T*> final { }; |
| 413 |
|
| 414 |
template<> |
| 415 |
struct PotentiallyFinal<int> final { }; |
| 416 |
|
| 417 |
struct FwdDeclFinal; |
| 418 |
using FwdDeclFinalAlias = FwdDeclFinal; |
| 419 |
struct FwdDeclFinal final {}; |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
void is_final() |
| 425 |
{ |
| 426 |
static_assert(__is_final(FinalClass)); |
| 427 |
static_assert(__is_final(PotentiallyFinal<float*>)); |
| 428 |
static_assert(__is_final(PotentiallyFinal<int>)); |
| 429 |
static_assert(__is_final(FwdDeclFinal)); |
| 430 |
static_assert(__is_final(FwdDeclFinalAlias)); |
| 431 |
|
| 432 |
static_assert(!__is_final(int)); |
| 433 |
static_assert(!__is_final(Union)); |
| 434 |
static_assert(!__is_final(Int)); |
| 435 |
static_assert(!__is_final(IntAr)); |
| 436 |
static_assert(!__is_final(UnionAr)); |
| 437 |
static_assert(!__is_final(Derives)); |
| 438 |
static_assert(!__is_final(ClassType)); |
| 439 |
static_assert(!__is_final(cvoid)); |
| 440 |
static_assert(!__is_final(IntArNB)); |
| 441 |
static_assert(!__is_final(HasAnonymousUnion)); |
| 442 |
} |
| 443 |
|
| 444 |
|
| 445 |
typedef HasVirt Polymorph; |
| 446 |
struct InheritPolymorph : Polymorph {}; |
| 447 |
|
| 448 |
void is_polymorphic() |
| 449 |
{ |
| 450 |
static_assert(__is_polymorphic(Polymorph)); |
| 451 |
static_assert(__is_polymorphic(InheritPolymorph)); |
| 452 |
|
| 453 |
static_assert(!__is_polymorphic(int)); |
| 454 |
static_assert(!__is_polymorphic(Union)); |
| 455 |
static_assert(!__is_polymorphic(IncompleteUnion)); |
| 456 |
static_assert(!__is_polymorphic(Int)); |
| 457 |
static_assert(!__is_polymorphic(IntAr)); |
| 458 |
static_assert(!__is_polymorphic(UnionAr)); |
| 459 |
static_assert(!__is_polymorphic(Derives)); |
| 460 |
static_assert(!__is_polymorphic(ClassType)); |
| 461 |
static_assert(!__is_polymorphic(Enum)); |
| 462 |
static_assert(!__is_polymorphic(cvoid)); |
| 463 |
static_assert(!__is_polymorphic(IntArNB)); |
| 464 |
} |
| 465 |
|
| 466 |
void is_integral() |
| 467 |
{ |
| 468 |
static_assert(__is_integral(bool)); |
| 469 |
static_assert(__is_integral(char)); |
| 470 |
static_assert(__is_integral(signed char)); |
| 471 |
static_assert(__is_integral(unsigned char)); |
| 472 |
//static_assert(__is_integral(char16_t)); |
| 473 |
//static_assert(__is_integral(char32_t)); |
| 474 |
static_assert(__is_integral(wchar_t)); |
| 475 |
static_assert(__is_integral(short)); |
| 476 |
static_assert(__is_integral(unsigned short)); |
| 477 |
static_assert(__is_integral(int)); |
| 478 |
static_assert(__is_integral(unsigned int)); |
| 479 |
static_assert(__is_integral(long)); |
| 480 |
static_assert(__is_integral(unsigned long)); |
| 481 |
|
| 482 |
static_assert(!__is_integral(float)); |
| 483 |
static_assert(!__is_integral(double)); |
| 484 |
static_assert(!__is_integral(long double)); |
| 485 |
static_assert(!__is_integral(Union)); |
| 486 |
static_assert(!__is_integral(UnionAr)); |
| 487 |
static_assert(!__is_integral(Derives)); |
| 488 |
static_assert(!__is_integral(ClassType)); |
| 489 |
static_assert(!__is_integral(Enum)); |
| 490 |
static_assert(!__is_integral(void)); |
| 491 |
static_assert(!__is_integral(cvoid)); |
| 492 |
static_assert(!__is_integral(IntArNB)); |
| 493 |
} |
| 494 |
|
| 495 |
void is_floating_point() |
| 496 |
{ |
| 497 |
static_assert(__is_floating_point(float)); |
| 498 |
static_assert(__is_floating_point(double)); |
| 499 |
static_assert(__is_floating_point(long double)); |
| 500 |
|
| 501 |
static_assert(!__is_floating_point(bool)); |
| 502 |
static_assert(!__is_floating_point(char)); |
| 503 |
static_assert(!__is_floating_point(signed char)); |
| 504 |
static_assert(!__is_floating_point(unsigned char)); |
| 505 |
//static_assert(!__is_floating_point(char16_t)); |
| 506 |
//static_assert(!__is_floating_point(char32_t)); |
| 507 |
static_assert(!__is_floating_point(wchar_t)); |
| 508 |
static_assert(!__is_floating_point(short)); |
| 509 |
static_assert(!__is_floating_point(unsigned short)); |
| 510 |
static_assert(!__is_floating_point(int)); |
| 511 |
static_assert(!__is_floating_point(unsigned int)); |
| 512 |
static_assert(!__is_floating_point(long)); |
| 513 |
static_assert(!__is_floating_point(unsigned long)); |
| 514 |
static_assert(!__is_floating_point(Union)); |
| 515 |
static_assert(!__is_floating_point(UnionAr)); |
| 516 |
static_assert(!__is_floating_point(Derives)); |
| 517 |
static_assert(!__is_floating_point(ClassType)); |
| 518 |
static_assert(!__is_floating_point(Enum)); |
| 519 |
static_assert(!__is_floating_point(void)); |
| 520 |
static_assert(!__is_floating_point(cvoid)); |
| 521 |
static_assert(!__is_floating_point(IntArNB)); |
| 522 |
} |
| 523 |
|
| 524 |
template <class T> |
| 525 |
struct AggregateTemplate { |
| 526 |
T value; |
| 527 |
}; |
| 528 |
|
| 529 |
template <class T> |
| 530 |
struct NonAggregateTemplate { |
| 531 |
T value; |
| 532 |
NonAggregateTemplate(); |
| 533 |
}; |
| 534 |
|
| 535 |
void is_aggregate() |
| 536 |
{ |
| 537 |
constexpr bool TrueAfterCpp11 = __cplusplus > 201103L; |
| 538 |
constexpr bool TrueAfterCpp14 = __cplusplus > 201402L; |
| 539 |
|
| 540 |
__is_aggregate(AnIncompleteType); // expected-error {{incomplete type}} |
| 541 |
__is_aggregate(IncompleteUnion); // expected-error {{incomplete type}} |
| 542 |
|
| 543 |
// Valid since LWG3823 |
| 544 |
static_assert(__is_aggregate(AnIncompleteType[])); |
| 545 |
static_assert(__is_aggregate(AnIncompleteType[1])); |
| 546 |
static_assert(__is_aggregate(AnIncompleteTypeAr)); |
| 547 |
static_assert(__is_aggregate(AnIncompleteTypeArNB)); |
| 548 |
static_assert(__is_aggregate(AnIncompleteTypeArMB)); |
| 549 |
|
| 550 |
static_assert(!__is_aggregate(NonPOD)); |
| 551 |
static_assert(__is_aggregate(NonPODAr)); |
| 552 |
static_assert(__is_aggregate(NonPODArNB)); |
| 553 |
static_assert(__is_aggregate(NonPODArMB)); |
| 554 |
|
| 555 |
static_assert(!__is_aggregate(Enum)); |
| 556 |
static_assert(__is_aggregate(POD)); |
| 557 |
static_assert(__is_aggregate(Empty)); |
| 558 |
static_assert(__is_aggregate(EmptyAr)); |
| 559 |
static_assert(__is_aggregate(EmptyArNB)); |
| 560 |
static_assert(__is_aggregate(EmptyArMB)); |
| 561 |
static_assert(!__is_aggregate(void)); |
| 562 |
static_assert(!__is_aggregate(const volatile void)); |
| 563 |
static_assert(!__is_aggregate(int)); |
| 564 |
static_assert(__is_aggregate(IntAr)); |
| 565 |
static_assert(__is_aggregate(IntArNB)); |
| 566 |
static_assert(__is_aggregate(EmptyUnion)); |
| 567 |
static_assert(__is_aggregate(Union)); |
| 568 |
static_assert(__is_aggregate(Statics)); |
| 569 |
static_assert(__is_aggregate(HasFunc)); |
| 570 |
static_assert(__is_aggregate(HasOp)); |
| 571 |
static_assert(__is_aggregate(HasAssign)); |
| 572 |
static_assert(__is_aggregate(HasAnonymousUnion)); |
| 573 |
|
| 574 |
static_assert(__is_aggregate(Derives) == TrueAfterCpp14); |
| 575 |
static_assert(__is_aggregate(DerivesAr)); |
| 576 |
static_assert(__is_aggregate(DerivesArNB)); |
| 577 |
static_assert(!__is_aggregate(HasCons)); |
| 578 |
#if __cplusplus >= 202002L |
| 579 |
static_assert(!__is_aggregate(HasDefaultCons)); |
| 580 |
#else |
| 581 |
static_assert(__is_aggregate(HasDefaultCons)); |
| 582 |
#endif |
| 583 |
static_assert(!__is_aggregate(HasExplicitDefaultCons)); |
| 584 |
static_assert(!__is_aggregate(HasInheritedCons)); |
| 585 |
static_assert(__is_aggregate(HasNoInheritedCons) == TrueAfterCpp14); |
| 586 |
static_assert(__is_aggregate(HasCopyAssign)); |
| 587 |
static_assert(!__is_aggregate(NonTrivialDefault)); |
| 588 |
static_assert(__is_aggregate(HasDest)); |
| 589 |
static_assert(!__is_aggregate(HasPriv)); |
| 590 |
static_assert(!__is_aggregate(HasProt)); |
| 591 |
static_assert(__is_aggregate(HasRefAggregate)); |
| 592 |
static_assert(__is_aggregate(HasNonPOD)); |
| 593 |
static_assert(!__is_aggregate(HasVirt)); |
| 594 |
static_assert(__is_aggregate(VirtAr)); |
| 595 |
static_assert(__is_aggregate(HasInClassInit) == TrueAfterCpp11); |
| 596 |
static_assert(!__is_aggregate(HasPrivateBase)); |
| 597 |
static_assert(!__is_aggregate(HasProtectedBase)); |
| 598 |
static_assert(!__is_aggregate(HasVirtBase)); |
| 599 |
|
| 600 |
static_assert(__is_aggregate(AggregateTemplate<int>)); |
| 601 |
static_assert(!__is_aggregate(NonAggregateTemplate<int>)); |
| 602 |
|
| 603 |
static_assert(__is_aggregate(Vector)); // Extension supported by GCC and Clang |
| 604 |
static_assert(__is_aggregate(VectorExt)); |
| 605 |
static_assert(__is_aggregate(ComplexInt)); |
| 606 |
static_assert(__is_aggregate(ComplexFloat)); |
| 607 |
} |
| 608 |
|
| 609 |
void is_arithmetic() |
| 610 |
{ |
| 611 |
static_assert(__is_arithmetic(float)); |
| 612 |
static_assert(__is_arithmetic(double)); |
| 613 |
static_assert(__is_arithmetic(long double)); |
| 614 |
static_assert(__is_arithmetic(bool)); |
| 615 |
static_assert(__is_arithmetic(char)); |
| 616 |
static_assert(__is_arithmetic(signed char)); |
| 617 |
static_assert(__is_arithmetic(unsigned char)); |
| 618 |
//static_assert(__is_arithmetic(char16_t)); |
| 619 |
//static_assert(__is_arithmetic(char32_t)); |
| 620 |
static_assert(__is_arithmetic(wchar_t)); |
| 621 |
static_assert(__is_arithmetic(short)); |
| 622 |
static_assert(__is_arithmetic(unsigned short)); |
| 623 |
static_assert(__is_arithmetic(int)); |
| 624 |
static_assert(__is_arithmetic(unsigned int)); |
| 625 |
static_assert(__is_arithmetic(long)); |
| 626 |
static_assert(__is_arithmetic(unsigned long)); |
| 627 |
|
| 628 |
static_assert(!__is_arithmetic(Union)); |
| 629 |
static_assert(!__is_arithmetic(UnionAr)); |
| 630 |
static_assert(!__is_arithmetic(Derives)); |
| 631 |
static_assert(!__is_arithmetic(ClassType)); |
| 632 |
static_assert(!__is_arithmetic(Enum)); |
| 633 |
static_assert(!__is_arithmetic(void)); |
| 634 |
static_assert(!__is_arithmetic(cvoid)); |
| 635 |
static_assert(!__is_arithmetic(IntArNB)); |
| 636 |
} |
| 637 |
|
| 638 |
void is_complete_type() |
| 639 |
{ |
| 640 |
static_assert(__is_complete_type(float)); |
| 641 |
static_assert(__is_complete_type(double)); |
| 642 |
static_assert(__is_complete_type(long double)); |
| 643 |
static_assert(__is_complete_type(bool)); |
| 644 |
static_assert(__is_complete_type(char)); |
| 645 |
static_assert(__is_complete_type(signed char)); |
| 646 |
static_assert(__is_complete_type(unsigned char)); |
| 647 |
//static_assert(__is_complete_type(char16_t)); |
| 648 |
//static_assert(__is_complete_type(char32_t)); |
| 649 |
static_assert(__is_complete_type(wchar_t)); |
| 650 |
static_assert(__is_complete_type(short)); |
| 651 |
static_assert(__is_complete_type(unsigned short)); |
| 652 |
static_assert(__is_complete_type(int)); |
| 653 |
static_assert(__is_complete_type(unsigned int)); |
| 654 |
static_assert(__is_complete_type(long)); |
| 655 |
static_assert(__is_complete_type(unsigned long)); |
| 656 |
static_assert(__is_complete_type(ACompleteType)); |
| 657 |
|
| 658 |
static_assert(!__is_complete_type(AnIncompleteType)); |
| 659 |
} |
| 660 |
|
| 661 |
void is_void() |
| 662 |
{ |
| 663 |
static_assert(__is_void(void)); |
| 664 |
static_assert(__is_void(cvoid)); |
| 665 |
|
| 666 |
static_assert(!__is_void(float)); |
| 667 |
static_assert(!__is_void(double)); |
| 668 |
static_assert(!__is_void(long double)); |
| 669 |
static_assert(!__is_void(bool)); |
| 670 |
static_assert(!__is_void(char)); |
| 671 |
static_assert(!__is_void(signed char)); |
| 672 |
static_assert(!__is_void(unsigned char)); |
| 673 |
static_assert(!__is_void(wchar_t)); |
| 674 |
static_assert(!__is_void(short)); |
| 675 |
static_assert(!__is_void(unsigned short)); |
| 676 |
static_assert(!__is_void(int)); |
| 677 |
static_assert(!__is_void(unsigned int)); |
| 678 |
static_assert(!__is_void(long)); |
| 679 |
static_assert(!__is_void(unsigned long)); |
| 680 |
static_assert(!__is_void(Union)); |
| 681 |
static_assert(!__is_void(UnionAr)); |
| 682 |
static_assert(!__is_void(Derives)); |
| 683 |
static_assert(!__is_void(ClassType)); |
| 684 |
static_assert(!__is_void(Enum)); |
| 685 |
static_assert(!__is_void(IntArNB)); |
| 686 |
static_assert(!__is_void(void*)); |
| 687 |
static_assert(!__is_void(cvoid*)); |
| 688 |
} |
| 689 |
|
| 690 |
void is_array() |
| 691 |
{ |
| 692 |
static_assert(__is_array(IntAr)); |
| 693 |
static_assert(__is_array(IntArNB)); |
| 694 |
static_assert(!__is_array(IntArZero)); |
| 695 |
static_assert(__is_array(UnionAr)); |
| 696 |
|
| 697 |
static_assert(!__is_array(void)); |
| 698 |
static_assert(!__is_array(cvoid)); |
| 699 |
static_assert(!__is_array(float)); |
| 700 |
static_assert(!__is_array(double)); |
| 701 |
static_assert(!__is_array(long double)); |
| 702 |
static_assert(!__is_array(bool)); |
| 703 |
static_assert(!__is_array(char)); |
| 704 |
static_assert(!__is_array(signed char)); |
| 705 |
static_assert(!__is_array(unsigned char)); |
| 706 |
static_assert(!__is_array(wchar_t)); |
| 707 |
static_assert(!__is_array(short)); |
| 708 |
static_assert(!__is_array(unsigned short)); |
| 709 |
static_assert(!__is_array(int)); |
| 710 |
static_assert(!__is_array(unsigned int)); |
| 711 |
static_assert(!__is_array(long)); |
| 712 |
static_assert(!__is_array(unsigned long)); |
| 713 |
static_assert(!__is_array(Union)); |
| 714 |
static_assert(!__is_array(Derives)); |
| 715 |
static_assert(!__is_array(ClassType)); |
| 716 |
static_assert(!__is_array(Enum)); |
| 717 |
static_assert(!__is_array(void*)); |
| 718 |
static_assert(!__is_array(cvoid*)); |
| 719 |
} |
| 720 |
|
| 721 |
void is_bounded_array(int n) { |
| 722 |
static_assert(__is_bounded_array(IntAr)); |
| 723 |
static_assert(!__is_bounded_array(IntArNB)); |
| 724 |
static_assert(!__is_bounded_array(IntArZero)); |
| 725 |
static_assert(__is_bounded_array(UnionAr)); |
| 726 |
|
| 727 |
static_assert(!__is_bounded_array(void)); |
| 728 |
static_assert(!__is_bounded_array(cvoid)); |
| 729 |
static_assert(!__is_bounded_array(float)); |
| 730 |
static_assert(!__is_bounded_array(double)); |
| 731 |
static_assert(!__is_bounded_array(long double)); |
| 732 |
static_assert(!__is_bounded_array(bool)); |
| 733 |
static_assert(!__is_bounded_array(char)); |
| 734 |
static_assert(!__is_bounded_array(signed char)); |
| 735 |
static_assert(!__is_bounded_array(unsigned char)); |
| 736 |
static_assert(!__is_bounded_array(wchar_t)); |
| 737 |
static_assert(!__is_bounded_array(short)); |
| 738 |
static_assert(!__is_bounded_array(unsigned short)); |
| 739 |
static_assert(!__is_bounded_array(int)); |
| 740 |
static_assert(!__is_bounded_array(unsigned int)); |
| 741 |
static_assert(!__is_bounded_array(long)); |
| 742 |
static_assert(!__is_bounded_array(unsigned long)); |
| 743 |
static_assert(!__is_bounded_array(Union)); |
| 744 |
static_assert(!__is_bounded_array(Derives)); |
| 745 |
static_assert(!__is_bounded_array(ClassType)); |
| 746 |
static_assert(!__is_bounded_array(Enum)); |
| 747 |
static_assert(!__is_bounded_array(void *)); |
| 748 |
static_assert(!__is_bounded_array(cvoid *)); |
| 749 |
|
| 750 |
int t32[n]; |
| 751 |
(void)__is_bounded_array(decltype(t32)); // expected-error{{variable length arrays are not supported in '__is_bounded_array'}} |
| 752 |
} |
| 753 |
|
| 754 |
void is_unbounded_array(int n) { |
| 755 |
static_assert(!__is_unbounded_array(IntAr)); |
| 756 |
static_assert(__is_unbounded_array(IntArNB)); |
| 757 |
static_assert(!__is_unbounded_array(IntArZero)); |
| 758 |
static_assert(!__is_unbounded_array(UnionAr)); |
| 759 |
|
| 760 |
static_assert(!__is_unbounded_array(void)); |
| 761 |
static_assert(!__is_unbounded_array(cvoid)); |
| 762 |
static_assert(!__is_unbounded_array(float)); |
| 763 |
static_assert(!__is_unbounded_array(double)); |
| 764 |
static_assert(!__is_unbounded_array(long double)); |
| 765 |
static_assert(!__is_unbounded_array(bool)); |
| 766 |
static_assert(!__is_unbounded_array(char)); |
| 767 |
static_assert(!__is_unbounded_array(signed char)); |
| 768 |
static_assert(!__is_unbounded_array(unsigned char)); |
| 769 |
static_assert(!__is_unbounded_array(wchar_t)); |
| 770 |
static_assert(!__is_unbounded_array(short)); |
| 771 |
static_assert(!__is_unbounded_array(unsigned short)); |
| 772 |
static_assert(!__is_unbounded_array(int)); |
| 773 |
static_assert(!__is_unbounded_array(unsigned int)); |
| 774 |
static_assert(!__is_unbounded_array(long)); |
| 775 |
static_assert(!__is_unbounded_array(unsigned long)); |
| 776 |
static_assert(!__is_unbounded_array(Union)); |
| 777 |
static_assert(!__is_unbounded_array(Derives)); |
| 778 |
static_assert(!__is_unbounded_array(ClassType)); |
| 779 |
static_assert(!__is_unbounded_array(Enum)); |
| 780 |
static_assert(!__is_unbounded_array(void *)); |
| 781 |
static_assert(!__is_unbounded_array(cvoid *)); |
| 782 |
|
| 783 |
int t32[n]; |
| 784 |
(void)__is_unbounded_array(decltype(t32)); // expected-error{{variable length arrays are not supported in '__is_unbounded_array'}} |
| 785 |
} |
| 786 |
|
| 787 |
template <typename T> void tmpl_func(T&) {} |
| 788 |
|
| 789 |
template <typename T> struct type_wrapper { |
| 790 |
typedef T type; |
| 791 |
typedef T* ptrtype; |
| 792 |
typedef T& reftype; |
| 793 |
}; |
| 794 |
|
| 795 |
void is_function() |
| 796 |
{ |
| 797 |
static_assert(__is_function(type_wrapper<void(void)>::type)); |
| 798 |
static_assert(__is_function(typeof(tmpl_func<int>))); |
| 799 |
|
| 800 |
typedef void (*ptr_to_func_type)(void); |
| 801 |
|
| 802 |
static_assert(!__is_function(void)); |
| 803 |
static_assert(!__is_function(cvoid)); |
| 804 |
static_assert(!__is_function(float)); |
| 805 |
static_assert(!__is_function(double)); |
| 806 |
static_assert(!__is_function(long double)); |
| 807 |
static_assert(!__is_function(bool)); |
| 808 |
static_assert(!__is_function(char)); |
| 809 |
static_assert(!__is_function(signed char)); |
| 810 |
static_assert(!__is_function(unsigned char)); |
| 811 |
static_assert(!__is_function(wchar_t)); |
| 812 |
static_assert(!__is_function(short)); |
| 813 |
static_assert(!__is_function(unsigned short)); |
| 814 |
static_assert(!__is_function(int)); |
| 815 |
static_assert(!__is_function(unsigned int)); |
| 816 |
static_assert(!__is_function(long)); |
| 817 |
static_assert(!__is_function(unsigned long)); |
| 818 |
static_assert(!__is_function(Union)); |
| 819 |
static_assert(!__is_function(Derives)); |
| 820 |
static_assert(!__is_function(ClassType)); |
| 821 |
static_assert(!__is_function(Enum)); |
| 822 |
static_assert(!__is_function(void*)); |
| 823 |
static_assert(!__is_function(cvoid*)); |
| 824 |
static_assert(!__is_function(void(*)())); |
| 825 |
static_assert(!__is_function(ptr_to_func_type)); |
| 826 |
static_assert(!__is_function(type_wrapper<void(void)>::ptrtype)); |
| 827 |
static_assert(!__is_function(type_wrapper<void(void)>::reftype)); |
| 828 |
} |
| 829 |
|
| 830 |
void is_reference() |
| 831 |
{ |
| 832 |
static_assert(__is_reference(int&)); |
| 833 |
static_assert(__is_reference(const int&)); |
| 834 |
static_assert(__is_reference(void *&)); |
| 835 |
|
| 836 |
static_assert(!__is_reference(int)); |
| 837 |
static_assert(!__is_reference(const int)); |
| 838 |
static_assert(!__is_reference(void *)); |
| 839 |
} |
| 840 |
|
| 841 |
void is_lvalue_reference() |
| 842 |
{ |
| 843 |
static_assert(__is_lvalue_reference(int&)); |
| 844 |
static_assert(__is_lvalue_reference(void *&)); |
| 845 |
static_assert(__is_lvalue_reference(const int&)); |
| 846 |
static_assert(__is_lvalue_reference(void * const &)); |
| 847 |
|
| 848 |
static_assert(!__is_lvalue_reference(int)); |
| 849 |
static_assert(!__is_lvalue_reference(const int)); |
| 850 |
static_assert(!__is_lvalue_reference(void *)); |
| 851 |
} |
| 852 |
|
| 853 |
#if __has_feature(cxx_rvalue_references) |
| 854 |
|
| 855 |
void is_rvalue_reference() |
| 856 |
{ |
| 857 |
static_assert(__is_rvalue_reference(const int&&)); |
| 858 |
static_assert(__is_rvalue_reference(void * const &&)); |
| 859 |
|
| 860 |
static_assert(!__is_rvalue_reference(int&)); |
| 861 |
static_assert(!__is_rvalue_reference(void *&)); |
| 862 |
static_assert(!__is_rvalue_reference(const int&)); |
| 863 |
static_assert(!__is_rvalue_reference(void * const &)); |
| 864 |
static_assert(!__is_rvalue_reference(int)); |
| 865 |
static_assert(!__is_rvalue_reference(const int)); |
| 866 |
static_assert(!__is_rvalue_reference(void *)); |
| 867 |
} |
| 868 |
|
| 869 |
#endif |
| 870 |
|
| 871 |
void is_fundamental() |
| 872 |
{ |
| 873 |
static_assert(__is_fundamental(float)); |
| 874 |
static_assert(__is_fundamental(double)); |
| 875 |
static_assert(__is_fundamental(long double)); |
| 876 |
static_assert(__is_fundamental(bool)); |
| 877 |
static_assert(__is_fundamental(char)); |
| 878 |
static_assert(__is_fundamental(signed char)); |
| 879 |
static_assert(__is_fundamental(unsigned char)); |
| 880 |
//static_assert(__is_fundamental(char16_t)); |
| 881 |
//static_assert(__is_fundamental(char32_t)); |
| 882 |
static_assert(__is_fundamental(wchar_t)); |
| 883 |
static_assert(__is_fundamental(short)); |
| 884 |
static_assert(__is_fundamental(unsigned short)); |
| 885 |
static_assert(__is_fundamental(int)); |
| 886 |
static_assert(__is_fundamental(unsigned int)); |
| 887 |
static_assert(__is_fundamental(long)); |
| 888 |
static_assert(__is_fundamental(unsigned long)); |
| 889 |
static_assert(__is_fundamental(void)); |
| 890 |
static_assert(__is_fundamental(cvoid)); |
| 891 |
static_assert(__is_fundamental(decltype(nullptr))); |
| 892 |
|
| 893 |
static_assert(!__is_fundamental(Union)); |
| 894 |
static_assert(!__is_fundamental(UnionAr)); |
| 895 |
static_assert(!__is_fundamental(Derives)); |
| 896 |
static_assert(!__is_fundamental(ClassType)); |
| 897 |
static_assert(!__is_fundamental(Enum)); |
| 898 |
static_assert(!__is_fundamental(IntArNB)); |
| 899 |
} |
| 900 |
|
| 901 |
void is_object() |
| 902 |
{ |
| 903 |
static_assert(__is_object(int)); |
| 904 |
static_assert(__is_object(int *)); |
| 905 |
static_assert(__is_object(void *)); |
| 906 |
static_assert(__is_object(Union)); |
| 907 |
static_assert(__is_object(UnionAr)); |
| 908 |
static_assert(__is_object(ClassType)); |
| 909 |
static_assert(__is_object(Enum)); |
| 910 |
|
| 911 |
static_assert(!__is_object(type_wrapper<void(void)>::type)); |
| 912 |
static_assert(!__is_object(int&)); |
| 913 |
static_assert(!__is_object(void)); |
| 914 |
} |
| 915 |
|
| 916 |
void is_scalar() |
| 917 |
{ |
| 918 |
static_assert(__is_scalar(float)); |
| 919 |
static_assert(__is_scalar(double)); |
| 920 |
static_assert(__is_scalar(long double)); |
| 921 |
static_assert(__is_scalar(bool)); |
| 922 |
static_assert(__is_scalar(char)); |
| 923 |
static_assert(__is_scalar(signed char)); |
| 924 |
static_assert(__is_scalar(unsigned char)); |
| 925 |
static_assert(__is_scalar(wchar_t)); |
| 926 |
static_assert(__is_scalar(short)); |
| 927 |
static_assert(__is_scalar(unsigned short)); |
| 928 |
static_assert(__is_scalar(int)); |
| 929 |
static_assert(__is_scalar(unsigned int)); |
| 930 |
static_assert(__is_scalar(long)); |
| 931 |
static_assert(__is_scalar(unsigned long)); |
| 932 |
static_assert(__is_scalar(Enum)); |
| 933 |
static_assert(__is_scalar(void*)); |
| 934 |
static_assert(__is_scalar(cvoid*)); |
| 935 |
|
| 936 |
static_assert(!__is_scalar(void)); |
| 937 |
static_assert(!__is_scalar(cvoid)); |
| 938 |
static_assert(!__is_scalar(Union)); |
| 939 |
static_assert(!__is_scalar(UnionAr)); |
| 940 |
static_assert(!__is_scalar(Derives)); |
| 941 |
static_assert(!__is_scalar(ClassType)); |
| 942 |
static_assert(!__is_scalar(IntArNB)); |
| 943 |
} |
| 944 |
|
| 945 |
struct StructWithMembers { |
| 946 |
int member; |
| 947 |
void method() {} |
| 948 |
}; |
| 949 |
|
| 950 |
void is_compound() |
| 951 |
{ |
| 952 |
static_assert(__is_compound(void*)); |
| 953 |
static_assert(__is_compound(cvoid*)); |
| 954 |
static_assert(__is_compound(void (*)())); |
| 955 |
static_assert(__is_compound(int StructWithMembers::*)); |
| 956 |
static_assert(__is_compound(void (StructWithMembers::*)())); |
| 957 |
static_assert(__is_compound(int&)); |
| 958 |
static_assert(__is_compound(Union)); |
| 959 |
static_assert(__is_compound(UnionAr)); |
| 960 |
static_assert(__is_compound(Derives)); |
| 961 |
static_assert(__is_compound(ClassType)); |
| 962 |
static_assert(__is_compound(IntArNB)); |
| 963 |
static_assert(__is_compound(Enum)); |
| 964 |
|
| 965 |
static_assert(!__is_compound(float)); |
| 966 |
static_assert(!__is_compound(double)); |
| 967 |
static_assert(!__is_compound(long double)); |
| 968 |
static_assert(!__is_compound(bool)); |
| 969 |
static_assert(!__is_compound(char)); |
| 970 |
static_assert(!__is_compound(signed char)); |
| 971 |
static_assert(!__is_compound(unsigned char)); |
| 972 |
static_assert(!__is_compound(wchar_t)); |
| 973 |
static_assert(!__is_compound(short)); |
| 974 |
static_assert(!__is_compound(unsigned short)); |
| 975 |
static_assert(!__is_compound(int)); |
| 976 |
static_assert(!__is_compound(unsigned int)); |
| 977 |
static_assert(!__is_compound(long)); |
| 978 |
static_assert(!__is_compound(unsigned long)); |
| 979 |
static_assert(!__is_compound(void)); |
| 980 |
static_assert(!__is_compound(cvoid)); |
| 981 |
} |
| 982 |
|
| 983 |
void is_pointer() |
| 984 |
{ |
| 985 |
StructWithMembers x; |
| 986 |
|
| 987 |
static_assert(__is_pointer(void*)); |
| 988 |
static_assert(__is_pointer(cvoid*)); |
| 989 |
static_assert(__is_pointer(cvoid*)); |
| 990 |
static_assert(__is_pointer(char*)); |
| 991 |
static_assert(__is_pointer(int*)); |
| 992 |
static_assert(__is_pointer(int**)); |
| 993 |
static_assert(__is_pointer(ClassType*)); |
| 994 |
static_assert(__is_pointer(Derives*)); |
| 995 |
static_assert(__is_pointer(Enum*)); |
| 996 |
static_assert(__is_pointer(IntArNB*)); |
| 997 |
static_assert(__is_pointer(Union*)); |
| 998 |
static_assert(__is_pointer(UnionAr*)); |
| 999 |
static_assert(__is_pointer(StructWithMembers*)); |
| 1000 |
static_assert(__is_pointer(void (*)())); |
| 1001 |
|
| 1002 |
static_assert(!__is_pointer(void)); |
| 1003 |
static_assert(!__is_pointer(cvoid)); |
| 1004 |
static_assert(!__is_pointer(cvoid)); |
| 1005 |
static_assert(!__is_pointer(char)); |
| 1006 |
static_assert(!__is_pointer(int)); |
| 1007 |
static_assert(!__is_pointer(int)); |
| 1008 |
static_assert(!__is_pointer(ClassType)); |
| 1009 |
static_assert(!__is_pointer(Derives)); |
| 1010 |
static_assert(!__is_pointer(Enum)); |
| 1011 |
static_assert(!__is_pointer(IntArNB)); |
| 1012 |
static_assert(!__is_pointer(Union)); |
| 1013 |
static_assert(!__is_pointer(UnionAr)); |
| 1014 |
static_assert(!__is_pointer(StructWithMembers)); |
| 1015 |
static_assert(!__is_pointer(int StructWithMembers::*)); |
| 1016 |
static_assert(!__is_pointer(void (StructWithMembers::*) ())); |
| 1017 |
} |
| 1018 |
|
| 1019 |
void is_member_object_pointer() |
| 1020 |
{ |
| 1021 |
StructWithMembers x; |
| 1022 |
|
| 1023 |
static_assert(__is_member_object_pointer(int StructWithMembers::*)); |
| 1024 |
|
| 1025 |
static_assert(!__is_member_object_pointer(void (StructWithMembers::*) ())); |
| 1026 |
static_assert(!__is_member_object_pointer(void*)); |
| 1027 |
static_assert(!__is_member_object_pointer(cvoid*)); |
| 1028 |
static_assert(!__is_member_object_pointer(cvoid*)); |
| 1029 |
static_assert(!__is_member_object_pointer(char*)); |
| 1030 |
static_assert(!__is_member_object_pointer(int*)); |
| 1031 |
static_assert(!__is_member_object_pointer(int**)); |
| 1032 |
static_assert(!__is_member_object_pointer(ClassType*)); |
| 1033 |
static_assert(!__is_member_object_pointer(Derives*)); |
| 1034 |
static_assert(!__is_member_object_pointer(Enum*)); |
| 1035 |
static_assert(!__is_member_object_pointer(IntArNB*)); |
| 1036 |
static_assert(!__is_member_object_pointer(Union*)); |
| 1037 |
static_assert(!__is_member_object_pointer(UnionAr*)); |
| 1038 |
static_assert(!__is_member_object_pointer(StructWithMembers*)); |
| 1039 |
static_assert(!__is_member_object_pointer(void)); |
| 1040 |
static_assert(!__is_member_object_pointer(cvoid)); |
| 1041 |
static_assert(!__is_member_object_pointer(cvoid)); |
| 1042 |
static_assert(!__is_member_object_pointer(char)); |
| 1043 |
static_assert(!__is_member_object_pointer(int)); |
| 1044 |
static_assert(!__is_member_object_pointer(int)); |
| 1045 |
static_assert(!__is_member_object_pointer(ClassType)); |
| 1046 |
static_assert(!__is_member_object_pointer(Derives)); |
| 1047 |
static_assert(!__is_member_object_pointer(Enum)); |
| 1048 |
static_assert(!__is_member_object_pointer(IntArNB)); |
| 1049 |
static_assert(!__is_member_object_pointer(Union)); |
| 1050 |
static_assert(!__is_member_object_pointer(UnionAr)); |
| 1051 |
static_assert(!__is_member_object_pointer(StructWithMembers)); |
| 1052 |
static_assert(!__is_member_object_pointer(void (*)())); |
| 1053 |
} |
| 1054 |
|
| 1055 |
void is_member_function_pointer() |
| 1056 |
{ |
| 1057 |
StructWithMembers x; |
| 1058 |
|
| 1059 |
static_assert(__is_member_function_pointer(void (StructWithMembers::*) ())); |
| 1060 |
|
| 1061 |
static_assert(!__is_member_function_pointer(int StructWithMembers::*)); |
| 1062 |
static_assert(!__is_member_function_pointer(void*)); |
| 1063 |
static_assert(!__is_member_function_pointer(cvoid*)); |
| 1064 |
static_assert(!__is_member_function_pointer(cvoid*)); |
| 1065 |
static_assert(!__is_member_function_pointer(char*)); |
| 1066 |
static_assert(!__is_member_function_pointer(int*)); |
| 1067 |
static_assert(!__is_member_function_pointer(int**)); |
| 1068 |
static_assert(!__is_member_function_pointer(ClassType*)); |
| 1069 |
static_assert(!__is_member_function_pointer(Derives*)); |
| 1070 |
static_assert(!__is_member_function_pointer(Enum*)); |
| 1071 |
static_assert(!__is_member_function_pointer(IntArNB*)); |
| 1072 |
static_assert(!__is_member_function_pointer(Union*)); |
| 1073 |
static_assert(!__is_member_function_pointer(UnionAr*)); |
| 1074 |
static_assert(!__is_member_function_pointer(StructWithMembers*)); |
| 1075 |
static_assert(!__is_member_function_pointer(void)); |
| 1076 |
static_assert(!__is_member_function_pointer(cvoid)); |
| 1077 |
static_assert(!__is_member_function_pointer(cvoid)); |
| 1078 |
static_assert(!__is_member_function_pointer(char)); |
| 1079 |
static_assert(!__is_member_function_pointer(int)); |
| 1080 |
static_assert(!__is_member_function_pointer(int)); |
| 1081 |
static_assert(!__is_member_function_pointer(ClassType)); |
| 1082 |
static_assert(!__is_member_function_pointer(Derives)); |
| 1083 |
static_assert(!__is_member_function_pointer(Enum)); |
| 1084 |
static_assert(!__is_member_function_pointer(IntArNB)); |
| 1085 |
static_assert(!__is_member_function_pointer(Union)); |
| 1086 |
static_assert(!__is_member_function_pointer(UnionAr)); |
| 1087 |
static_assert(!__is_member_function_pointer(StructWithMembers)); |
| 1088 |
static_assert(!__is_member_function_pointer(void (*)())); |
| 1089 |
} |
| 1090 |
|
| 1091 |
void is_member_pointer() |
| 1092 |
{ |
| 1093 |
StructWithMembers x; |
| 1094 |
|
| 1095 |
static_assert(__is_member_pointer(int StructWithMembers::*)); |
| 1096 |
static_assert(__is_member_pointer(void (StructWithMembers::*) ())); |
| 1097 |
|
| 1098 |
static_assert(!__is_member_pointer(void*)); |
| 1099 |
static_assert(!__is_member_pointer(cvoid*)); |
| 1100 |
static_assert(!__is_member_pointer(cvoid*)); |
| 1101 |
static_assert(!__is_member_pointer(char*)); |
| 1102 |
static_assert(!__is_member_pointer(int*)); |
| 1103 |
static_assert(!__is_member_pointer(int**)); |
| 1104 |
static_assert(!__is_member_pointer(ClassType*)); |
| 1105 |
static_assert(!__is_member_pointer(Derives*)); |
| 1106 |
static_assert(!__is_member_pointer(Enum*)); |
| 1107 |
static_assert(!__is_member_pointer(IntArNB*)); |
| 1108 |
static_assert(!__is_member_pointer(Union*)); |
| 1109 |
static_assert(!__is_member_pointer(UnionAr*)); |
| 1110 |
static_assert(!__is_member_pointer(StructWithMembers*)); |
| 1111 |
static_assert(!__is_member_pointer(void)); |
| 1112 |
static_assert(!__is_member_pointer(cvoid)); |
| 1113 |
static_assert(!__is_member_pointer(cvoid)); |
| 1114 |
static_assert(!__is_member_pointer(char)); |
| 1115 |
static_assert(!__is_member_pointer(int)); |
| 1116 |
static_assert(!__is_member_pointer(int)); |
| 1117 |
static_assert(!__is_member_pointer(ClassType)); |
| 1118 |
static_assert(!__is_member_pointer(Derives)); |
| 1119 |
static_assert(!__is_member_pointer(Enum)); |
| 1120 |
static_assert(!__is_member_pointer(IntArNB)); |
| 1121 |
static_assert(!__is_member_pointer(Union)); |
| 1122 |
static_assert(!__is_member_pointer(UnionAr)); |
| 1123 |
static_assert(!__is_member_pointer(StructWithMembers)); |
| 1124 |
static_assert(!__is_member_pointer(void (*)())); |
| 1125 |
} |
| 1126 |
|
| 1127 |
void is_const() |
| 1128 |
{ |
| 1129 |
static_assert(__is_const(cvoid)); |
| 1130 |
static_assert(__is_const(const char)); |
| 1131 |
static_assert(__is_const(const int)); |
| 1132 |
static_assert(__is_const(const long)); |
| 1133 |
static_assert(__is_const(const short)); |
| 1134 |
static_assert(__is_const(const signed char)); |
| 1135 |
static_assert(__is_const(const wchar_t)); |
| 1136 |
static_assert(__is_const(const bool)); |
| 1137 |
static_assert(__is_const(const float)); |
| 1138 |
static_assert(__is_const(const double)); |
| 1139 |
static_assert(__is_const(const long double)); |
| 1140 |
static_assert(__is_const(const unsigned char)); |
| 1141 |
static_assert(__is_const(const unsigned int)); |
| 1142 |
static_assert(__is_const(const unsigned long long)); |
| 1143 |
static_assert(__is_const(const unsigned long)); |
| 1144 |
static_assert(__is_const(const unsigned short)); |
| 1145 |
static_assert(__is_const(const void)); |
| 1146 |
static_assert(__is_const(const ClassType)); |
| 1147 |
static_assert(__is_const(const Derives)); |
| 1148 |
static_assert(__is_const(const Enum)); |
| 1149 |
static_assert(__is_const(const IntArNB)); |
| 1150 |
static_assert(__is_const(const Union)); |
| 1151 |
static_assert(__is_const(const UnionAr)); |
| 1152 |
|
| 1153 |
static_assert(!__is_const(char)); |
| 1154 |
static_assert(!__is_const(int)); |
| 1155 |
static_assert(!__is_const(long)); |
| 1156 |
static_assert(!__is_const(short)); |
| 1157 |
static_assert(!__is_const(signed char)); |
| 1158 |
static_assert(!__is_const(wchar_t)); |
| 1159 |
static_assert(!__is_const(bool)); |
| 1160 |
static_assert(!__is_const(float)); |
| 1161 |
static_assert(!__is_const(double)); |
| 1162 |
static_assert(!__is_const(long double)); |
| 1163 |
static_assert(!__is_const(unsigned char)); |
| 1164 |
static_assert(!__is_const(unsigned int)); |
| 1165 |
static_assert(!__is_const(unsigned long long)); |
| 1166 |
static_assert(!__is_const(unsigned long)); |
| 1167 |
static_assert(!__is_const(unsigned short)); |
| 1168 |
static_assert(!__is_const(void)); |
| 1169 |
static_assert(!__is_const(ClassType)); |
| 1170 |
static_assert(!__is_const(Derives)); |
| 1171 |
static_assert(!__is_const(Enum)); |
| 1172 |
static_assert(!__is_const(IntArNB)); |
| 1173 |
static_assert(!__is_const(Union)); |
| 1174 |
static_assert(!__is_const(UnionAr)); |
| 1175 |
} |
| 1176 |
|
| 1177 |
void is_volatile() |
| 1178 |
{ |
| 1179 |
static_assert(__is_volatile(volatile char)); |
| 1180 |
static_assert(__is_volatile(volatile int)); |
| 1181 |
static_assert(__is_volatile(volatile long)); |
| 1182 |
static_assert(__is_volatile(volatile short)); |
| 1183 |
static_assert(__is_volatile(volatile signed char)); |
| 1184 |
static_assert(__is_volatile(volatile wchar_t)); |
| 1185 |
static_assert(__is_volatile(volatile bool)); |
| 1186 |
static_assert(__is_volatile(volatile float)); |
| 1187 |
static_assert(__is_volatile(volatile double)); |
| 1188 |
static_assert(__is_volatile(volatile long double)); |
| 1189 |
static_assert(__is_volatile(volatile unsigned char)); |
| 1190 |
static_assert(__is_volatile(volatile unsigned int)); |
| 1191 |
static_assert(__is_volatile(volatile unsigned long long)); |
| 1192 |
static_assert(__is_volatile(volatile unsigned long)); |
| 1193 |
static_assert(__is_volatile(volatile unsigned short)); |
| 1194 |
static_assert(__is_volatile(volatile void)); |
| 1195 |
static_assert(__is_volatile(volatile ClassType)); |
| 1196 |
static_assert(__is_volatile(volatile Derives)); |
| 1197 |
static_assert(__is_volatile(volatile Enum)); |
| 1198 |
static_assert(__is_volatile(volatile IntArNB)); |
| 1199 |
static_assert(__is_volatile(volatile Union)); |
| 1200 |
static_assert(__is_volatile(volatile UnionAr)); |
| 1201 |
|
| 1202 |
static_assert(!__is_volatile(char)); |
| 1203 |
static_assert(!__is_volatile(int)); |
| 1204 |
static_assert(!__is_volatile(long)); |
| 1205 |
static_assert(!__is_volatile(short)); |
| 1206 |
static_assert(!__is_volatile(signed char)); |
| 1207 |
static_assert(!__is_volatile(wchar_t)); |
| 1208 |
static_assert(!__is_volatile(bool)); |
| 1209 |
static_assert(!__is_volatile(float)); |
| 1210 |
static_assert(!__is_volatile(double)); |
| 1211 |
static_assert(!__is_volatile(long double)); |
| 1212 |
static_assert(!__is_volatile(unsigned char)); |
| 1213 |
static_assert(!__is_volatile(unsigned int)); |
| 1214 |
static_assert(!__is_volatile(unsigned long long)); |
| 1215 |
static_assert(!__is_volatile(unsigned long)); |
| 1216 |
static_assert(!__is_volatile(unsigned short)); |
| 1217 |
static_assert(!__is_volatile(void)); |
| 1218 |
static_assert(!__is_volatile(ClassType)); |
| 1219 |
static_assert(!__is_volatile(Derives)); |
| 1220 |
static_assert(!__is_volatile(Enum)); |
| 1221 |
static_assert(!__is_volatile(IntArNB)); |
| 1222 |
static_assert(!__is_volatile(Union)); |
| 1223 |
static_assert(!__is_volatile(UnionAr)); |
| 1224 |
} |
| 1225 |
|
| 1226 |
struct TrivialStruct { |
| 1227 |
int member; |
| 1228 |
}; |
| 1229 |
|
| 1230 |
struct NonTrivialStruct { |
| 1231 |
int member; |
| 1232 |
NonTrivialStruct() { |
| 1233 |
member = 0; |
| 1234 |
} |
| 1235 |
}; |
| 1236 |
|
| 1237 |
struct SuperNonTrivialStruct { |
| 1238 |
SuperNonTrivialStruct() { } |
| 1239 |
~SuperNonTrivialStruct() { } |
| 1240 |
}; |
| 1241 |
|
| 1242 |
struct NonTCStruct { |
| 1243 |
NonTCStruct(const NonTCStruct&) {} |
| 1244 |
}; |
| 1245 |
|
| 1246 |
struct AllDefaulted { |
| 1247 |
AllDefaulted() = default; |
| 1248 |
AllDefaulted(const AllDefaulted &) = default; |
| 1249 |
AllDefaulted(AllDefaulted &&) = default; |
| 1250 |
AllDefaulted &operator=(const AllDefaulted &) = default; |
| 1251 |
AllDefaulted &operator=(AllDefaulted &&) = default; |
| 1252 |
~AllDefaulted() = default; |
| 1253 |
}; |
| 1254 |
|
| 1255 |
struct NoDefaultMoveAssignDueToUDCopyCtor { |
| 1256 |
NoDefaultMoveAssignDueToUDCopyCtor(const NoDefaultMoveAssignDueToUDCopyCtor&); |
| 1257 |
}; |
| 1258 |
|
| 1259 |
struct NoDefaultMoveAssignDueToUDCopyAssign { |
| 1260 |
NoDefaultMoveAssignDueToUDCopyAssign& operator=( |
| 1261 |
const NoDefaultMoveAssignDueToUDCopyAssign&); |
| 1262 |
}; |
| 1263 |
|
| 1264 |
struct NoDefaultMoveAssignDueToDtor { |
| 1265 |
~NoDefaultMoveAssignDueToDtor(); |
| 1266 |
}; |
| 1267 |
|
| 1268 |
struct AllDeleted { |
| 1269 |
AllDeleted() = delete; |
| 1270 |
AllDeleted(const AllDeleted &) = delete; |
| 1271 |
AllDeleted(AllDeleted &&) = delete; |
| 1272 |
AllDeleted &operator=(const AllDeleted &) = delete; |
| 1273 |
AllDeleted &operator=(AllDeleted &&) = delete; |
| 1274 |
~AllDeleted() = delete; |
| 1275 |
}; |
| 1276 |
|
| 1277 |
struct ExtDefaulted { |
| 1278 |
ExtDefaulted(); |
| 1279 |
ExtDefaulted(const ExtDefaulted &); |
| 1280 |
ExtDefaulted(ExtDefaulted &&); |
| 1281 |
ExtDefaulted &operator=(const ExtDefaulted &); |
| 1282 |
ExtDefaulted &operator=(ExtDefaulted &&); |
| 1283 |
~ExtDefaulted(); |
| 1284 |
}; |
| 1285 |
|
| 1286 |
// Despite being defaulted, these functions are not trivial. |
| 1287 |
ExtDefaulted::ExtDefaulted() = default; |
| 1288 |
ExtDefaulted::ExtDefaulted(const ExtDefaulted &) = default; |
| 1289 |
ExtDefaulted::ExtDefaulted(ExtDefaulted &&) = default; |
| 1290 |
ExtDefaulted &ExtDefaulted::operator=(const ExtDefaulted &) = default; |
| 1291 |
ExtDefaulted &ExtDefaulted::operator=(ExtDefaulted &&) = default; |
| 1292 |
ExtDefaulted::~ExtDefaulted() = default; |
| 1293 |
|
| 1294 |
void is_trivial2() |
| 1295 |
{ |
| 1296 |
static_assert(__is_trivial(char)); |
| 1297 |
static_assert(__is_trivial(int)); |
| 1298 |
static_assert(__is_trivial(long)); |
| 1299 |
static_assert(__is_trivial(short)); |
| 1300 |
static_assert(__is_trivial(signed char)); |
| 1301 |
static_assert(__is_trivial(wchar_t)); |
| 1302 |
static_assert(__is_trivial(bool)); |
| 1303 |
static_assert(__is_trivial(float)); |
| 1304 |
static_assert(__is_trivial(double)); |
| 1305 |
static_assert(__is_trivial(long double)); |
| 1306 |
static_assert(__is_trivial(unsigned char)); |
| 1307 |
static_assert(__is_trivial(unsigned int)); |
| 1308 |
static_assert(__is_trivial(unsigned long long)); |
| 1309 |
static_assert(__is_trivial(unsigned long)); |
| 1310 |
static_assert(__is_trivial(unsigned short)); |
| 1311 |
static_assert(__is_trivial(ClassType)); |
| 1312 |
static_assert(__is_trivial(Derives)); |
| 1313 |
static_assert(__is_trivial(Enum)); |
| 1314 |
static_assert(__is_trivial(IntAr)); |
| 1315 |
static_assert(__is_trivial(Union)); |
| 1316 |
static_assert(__is_trivial(UnionAr)); |
| 1317 |
static_assert(__is_trivial(TrivialStruct)); |
| 1318 |
static_assert(__is_trivial(AllDefaulted)); |
| 1319 |
static_assert(__is_trivial(AllDeleted)); |
| 1320 |
|
| 1321 |
static_assert(!__is_trivial(void)); |
| 1322 |
static_assert(!__is_trivial(NonTrivialStruct)); |
| 1323 |
static_assert(!__is_trivial(SuperNonTrivialStruct)); |
| 1324 |
static_assert(!__is_trivial(NonTCStruct)); |
| 1325 |
static_assert(!__is_trivial(ExtDefaulted)); |
| 1326 |
|
| 1327 |
static_assert(__is_trivial(ACompleteType)); |
| 1328 |
static_assert(!__is_trivial(AnIncompleteType)); // expected-error {{incomplete type}} |
| 1329 |
static_assert(!__is_trivial(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 1330 |
static_assert(!__is_trivial(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 1331 |
static_assert(!__is_trivial(void)); |
| 1332 |
static_assert(!__is_trivial(const volatile void)); |
| 1333 |
} |
| 1334 |
|
| 1335 |
void is_trivially_copyable2() |
| 1336 |
{ |
| 1337 |
static_assert(__is_trivially_copyable(char)); |
| 1338 |
static_assert(__is_trivially_copyable(int)); |
| 1339 |
static_assert(__is_trivially_copyable(long)); |
| 1340 |
static_assert(__is_trivially_copyable(short)); |
| 1341 |
static_assert(__is_trivially_copyable(signed char)); |
| 1342 |
static_assert(__is_trivially_copyable(wchar_t)); |
| 1343 |
static_assert(__is_trivially_copyable(bool)); |
| 1344 |
static_assert(__is_trivially_copyable(float)); |
| 1345 |
static_assert(__is_trivially_copyable(double)); |
| 1346 |
static_assert(__is_trivially_copyable(long double)); |
| 1347 |
static_assert(__is_trivially_copyable(unsigned char)); |
| 1348 |
static_assert(__is_trivially_copyable(unsigned int)); |
| 1349 |
static_assert(__is_trivially_copyable(unsigned long long)); |
| 1350 |
static_assert(__is_trivially_copyable(unsigned long)); |
| 1351 |
static_assert(__is_trivially_copyable(unsigned short)); |
| 1352 |
static_assert(__is_trivially_copyable(ClassType)); |
| 1353 |
static_assert(__is_trivially_copyable(Derives)); |
| 1354 |
static_assert(__is_trivially_copyable(Enum)); |
| 1355 |
static_assert(__is_trivially_copyable(IntAr)); |
| 1356 |
static_assert(__is_trivially_copyable(Union)); |
| 1357 |
static_assert(__is_trivially_copyable(UnionAr)); |
| 1358 |
static_assert(__is_trivially_copyable(TrivialStruct)); |
| 1359 |
static_assert(__is_trivially_copyable(NonTrivialStruct)); |
| 1360 |
static_assert(__is_trivially_copyable(AllDefaulted)); |
| 1361 |
static_assert(__is_trivially_copyable(AllDeleted)); |
| 1362 |
|
| 1363 |
static_assert(!__is_trivially_copyable(void)); |
| 1364 |
static_assert(!__is_trivially_copyable(SuperNonTrivialStruct)); |
| 1365 |
static_assert(!__is_trivially_copyable(NonTCStruct)); |
| 1366 |
static_assert(!__is_trivially_copyable(ExtDefaulted)); |
| 1367 |
|
| 1368 |
static_assert(__is_trivially_copyable(const int)); |
| 1369 |
static_assert(__is_trivially_copyable(volatile int)); |
| 1370 |
|
| 1371 |
static_assert(__is_trivially_copyable(ACompleteType)); |
| 1372 |
static_assert(!__is_trivially_copyable(AnIncompleteType)); // expected-error {{incomplete type}} |
| 1373 |
static_assert(!__is_trivially_copyable(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 1374 |
static_assert(!__is_trivially_copyable(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 1375 |
static_assert(!__is_trivially_copyable(void)); |
| 1376 |
static_assert(!__is_trivially_copyable(const volatile void)); |
| 1377 |
} |
| 1378 |
|
| 1379 |
struct CStruct { |
| 1380 |
int one; |
| 1381 |
int two; |
| 1382 |
}; |
| 1383 |
|
| 1384 |
struct CEmptyStruct {}; |
| 1385 |
|
| 1386 |
struct CppEmptyStruct : CStruct {}; |
| 1387 |
struct CppStructStandard : CEmptyStruct { |
| 1388 |
int three; |
| 1389 |
int four; |
| 1390 |
}; |
| 1391 |
struct CppStructNonStandardByBase : CStruct { |
| 1392 |
int three; |
| 1393 |
int four; |
| 1394 |
}; |
| 1395 |
struct CppStructNonStandardByVirt : CStruct { |
| 1396 |
virtual void method() {} |
| 1397 |
}; |
| 1398 |
struct CppStructNonStandardByMemb : CStruct { |
| 1399 |
CppStructNonStandardByVirt member; |
| 1400 |
}; |
| 1401 |
struct CppStructNonStandardByProt : CStruct { |
| 1402 |
int five; |
| 1403 |
protected: |
| 1404 |
int six; |
| 1405 |
}; |
| 1406 |
struct CppStructNonStandardByVirtBase : virtual CStruct { |
| 1407 |
}; |
| 1408 |
struct CppStructNonStandardBySameBase : CEmptyStruct { |
| 1409 |
CEmptyStruct member; |
| 1410 |
}; |
| 1411 |
struct CppStructNonStandardBy2ndVirtBase : CEmptyStruct { |
| 1412 |
CEmptyStruct member; |
| 1413 |
}; |
| 1414 |
|
| 1415 |
void is_standard_layout() |
| 1416 |
{ |
| 1417 |
typedef const int ConstInt; |
| 1418 |
typedef ConstInt ConstIntAr[4]; |
| 1419 |
typedef CppStructStandard CppStructStandardAr[4]; |
| 1420 |
|
| 1421 |
static_assert(__is_standard_layout(int)); |
| 1422 |
static_assert(__is_standard_layout(ConstInt)); |
| 1423 |
static_assert(__is_standard_layout(ConstIntAr)); |
| 1424 |
static_assert(__is_standard_layout(CStruct)); |
| 1425 |
static_assert(__is_standard_layout(CppStructStandard)); |
| 1426 |
static_assert(__is_standard_layout(CppStructStandardAr)); |
| 1427 |
static_assert(__is_standard_layout(Vector)); |
| 1428 |
static_assert(__is_standard_layout(VectorExt)); |
| 1429 |
|
| 1430 |
typedef CppStructNonStandardByBase CppStructNonStandardByBaseAr[4]; |
| 1431 |
|
| 1432 |
static_assert(!__is_standard_layout(CppStructNonStandardByVirt)); |
| 1433 |
static_assert(!__is_standard_layout(CppStructNonStandardByMemb)); |
| 1434 |
static_assert(!__is_standard_layout(CppStructNonStandardByProt)); |
| 1435 |
static_assert(!__is_standard_layout(CppStructNonStandardByVirtBase)); |
| 1436 |
static_assert(!__is_standard_layout(CppStructNonStandardByBase)); |
| 1437 |
static_assert(!__is_standard_layout(CppStructNonStandardByBaseAr)); |
| 1438 |
static_assert(!__is_standard_layout(CppStructNonStandardBySameBase)); |
| 1439 |
static_assert(!__is_standard_layout(CppStructNonStandardBy2ndVirtBase)); |
| 1440 |
|
| 1441 |
static_assert(__is_standard_layout(ACompleteType)); |
| 1442 |
static_assert(!__is_standard_layout(AnIncompleteType)); // expected-error {{incomplete type}} |
| 1443 |
static_assert(!__is_standard_layout(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 1444 |
static_assert(!__is_standard_layout(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 1445 |
static_assert(!__is_standard_layout(void)); |
| 1446 |
static_assert(!__is_standard_layout(const volatile void)); |
| 1447 |
|
| 1448 |
struct HasAnonEmptyBitfield { int : 0; }; |
| 1449 |
struct HasAnonBitfield { int : 4; }; |
| 1450 |
struct DerivesFromBitfield : HasAnonBitfield {}; |
| 1451 |
struct DerivesFromBitfieldWithBitfield : HasAnonBitfield { int : 5; }; |
| 1452 |
struct DerivesFromBitfieldTwice : DerivesFromBitfield, HasAnonEmptyBitfield {}; |
| 1453 |
|
| 1454 |
static_assert(__is_standard_layout(HasAnonEmptyBitfield)); |
| 1455 |
static_assert(__is_standard_layout(HasAnonBitfield)); |
| 1456 |
static_assert(__is_standard_layout(DerivesFromBitfield)); |
| 1457 |
static_assert(!__is_standard_layout(DerivesFromBitfieldWithBitfield)); |
| 1458 |
static_assert(!__is_standard_layout(DerivesFromBitfieldTwice)); |
| 1459 |
|
| 1460 |
struct Empty {}; |
| 1461 |
struct HasEmptyBase : Empty {}; |
| 1462 |
struct HoldsEmptyBase { Empty e; }; |
| 1463 |
struct HasRepeatedEmptyBase : Empty, HasEmptyBase {}; // expected-warning {{inaccessible}} |
| 1464 |
struct HasEmptyBaseAsMember : Empty { Empty e; }; |
| 1465 |
struct HasEmptyBaseAsSubobjectOfMember1 : Empty { HoldsEmptyBase e; }; |
| 1466 |
struct HasEmptyBaseAsSubobjectOfMember2 : Empty { HasEmptyBase e; }; |
| 1467 |
struct HasEmptyBaseAsSubobjectOfMember3 : Empty { HoldsEmptyBase e[2]; }; |
| 1468 |
struct HasEmptyIndirectBaseAsMember : HasEmptyBase { Empty e; }; |
| 1469 |
struct HasEmptyIndirectBaseAsSecondMember : HasEmptyBase { int n; Empty e; }; |
| 1470 |
struct HasEmptyIndirectBaseAfterBitfield : HasEmptyBase { int : 4; Empty e; }; |
| 1471 |
|
| 1472 |
static_assert(__is_standard_layout(Empty)); |
| 1473 |
static_assert(__is_standard_layout(HasEmptyBase)); |
| 1474 |
static_assert(!__is_standard_layout(HasRepeatedEmptyBase)); |
| 1475 |
static_assert(!__is_standard_layout(HasEmptyBaseAsMember)); |
| 1476 |
static_assert(!__is_standard_layout(HasEmptyBaseAsSubobjectOfMember1)); |
| 1477 |
static_assert(__is_standard_layout(HasEmptyBaseAsSubobjectOfMember2)); // FIXME: standard bug? |
| 1478 |
static_assert(!__is_standard_layout(HasEmptyBaseAsSubobjectOfMember3)); |
| 1479 |
static_assert(!__is_standard_layout(HasEmptyIndirectBaseAsMember)); |
| 1480 |
static_assert(__is_standard_layout(HasEmptyIndirectBaseAsSecondMember)); |
| 1481 |
static_assert(!__is_standard_layout(HasEmptyIndirectBaseAfterBitfield)); // FIXME: standard bug? |
| 1482 |
|
| 1483 |
struct StructWithEmptyFields { |
| 1484 |
int n; |
| 1485 |
HoldsEmptyBase e[3]; |
| 1486 |
}; |
| 1487 |
union UnionWithEmptyFields { |
| 1488 |
int n; |
| 1489 |
HoldsEmptyBase e[3]; |
| 1490 |
}; |
| 1491 |
struct HasEmptyIndirectBaseAsSecondStructMember : HasEmptyBase { |
| 1492 |
StructWithEmptyFields u; |
| 1493 |
}; |
| 1494 |
struct HasEmptyIndirectBaseAsSecondUnionMember : HasEmptyBase { |
| 1495 |
UnionWithEmptyFields u; |
| 1496 |
}; |
| 1497 |
|
| 1498 |
static_assert(__is_standard_layout(HasEmptyIndirectBaseAsSecondStructMember)); |
| 1499 |
static_assert(!__is_standard_layout(HasEmptyIndirectBaseAsSecondUnionMember)); |
| 1500 |
} |
| 1501 |
|
| 1502 |
struct CStruct2 { |
| 1503 |
int one; |
| 1504 |
int two; |
| 1505 |
}; |
| 1506 |
|
| 1507 |
struct CEmptyStruct2 {}; |
| 1508 |
|
| 1509 |
struct CppEmptyStruct2 : CStruct2 {}; |
| 1510 |
struct CppStructStandard2 : CEmptyStruct2 { |
| 1511 |
int three; |
| 1512 |
int four; |
| 1513 |
}; |
| 1514 |
struct CppStructNonStandardByBase2 : CStruct2 { |
| 1515 |
int three; |
| 1516 |
int four; |
| 1517 |
}; |
| 1518 |
struct CppStructNonStandardByVirt2 : CStruct2 { |
| 1519 |
virtual void method() {} |
| 1520 |
}; |
| 1521 |
struct CppStructNonStandardByMemb2 : CStruct2 { |
| 1522 |
CppStructNonStandardByVirt member; |
| 1523 |
}; |
| 1524 |
struct CppStructNonStandardByProt2 : CStruct2 { |
| 1525 |
int five; |
| 1526 |
protected: |
| 1527 |
int six; |
| 1528 |
}; |
| 1529 |
struct CppStructNonStandardByVirtBase2 : virtual CStruct2 { |
| 1530 |
}; |
| 1531 |
struct CppStructNonStandardBySameBase2 : CEmptyStruct2 { |
| 1532 |
CEmptyStruct member; |
| 1533 |
}; |
| 1534 |
struct CppStructNonStandardBy2ndVirtBase2 : CEmptyStruct2 { |
| 1535 |
CEmptyStruct member; |
| 1536 |
}; |
| 1537 |
|
| 1538 |
struct CStructWithQualifiers { |
| 1539 |
const int one; |
| 1540 |
volatile int two; |
| 1541 |
}; |
| 1542 |
|
| 1543 |
struct CStructNoUniqueAddress { |
| 1544 |
int one; |
| 1545 |
[[no_unique_address]] int two; |
| 1546 |
}; |
| 1547 |
|
| 1548 |
struct CStructNoUniqueAddress2 { |
| 1549 |
int one; |
| 1550 |
[[no_unique_address]] int two; |
| 1551 |
}; |
| 1552 |
|
| 1553 |
struct alignas(64) CStructAlignment { |
| 1554 |
int one; |
| 1555 |
int two; |
| 1556 |
}; |
| 1557 |
|
| 1558 |
struct CStructAlignedMembers { |
| 1559 |
int one; |
| 1560 |
alignas(16) int two; |
| 1561 |
}; |
| 1562 |
|
| 1563 |
enum EnumLayout : int {}; |
| 1564 |
enum class EnumClassLayout {}; |
| 1565 |
enum EnumForward : int; |
| 1566 |
enum class EnumClassForward; |
| 1567 |
|
| 1568 |
struct CStructIncomplete; // #CStructIncomplete |
| 1569 |
|
| 1570 |
struct CStructNested { |
| 1571 |
int a; |
| 1572 |
CStruct s; |
| 1573 |
int b; |
| 1574 |
}; |
| 1575 |
|
| 1576 |
struct CStructNested2 { |
| 1577 |
int a2; |
| 1578 |
CStruct s2; |
| 1579 |
int b2; |
| 1580 |
}; |
| 1581 |
|
| 1582 |
struct CStructWithBitfelds { |
| 1583 |
int a : 5; |
| 1584 |
int : 0; |
| 1585 |
}; |
| 1586 |
|
| 1587 |
struct CStructWithBitfelds2 { |
| 1588 |
int a : 5; |
| 1589 |
int : 0; |
| 1590 |
}; |
| 1591 |
|
| 1592 |
struct CStructWithBitfelds3 { |
| 1593 |
int : 0; |
| 1594 |
int b : 5; |
| 1595 |
}; |
| 1596 |
|
| 1597 |
struct CStructWithBitfelds4 { |
| 1598 |
EnumLayout a : 5; |
| 1599 |
int : 0; |
| 1600 |
}; |
| 1601 |
|
| 1602 |
union UnionLayout { |
| 1603 |
int a; |
| 1604 |
double b; |
| 1605 |
CStruct c; |
| 1606 |
[[no_unique_address]] CEmptyStruct d; |
| 1607 |
[[no_unique_address]] CEmptyStruct2 e; |
| 1608 |
}; |
| 1609 |
|
| 1610 |
union UnionLayout2 { |
| 1611 |
CStruct c; |
| 1612 |
int a; |
| 1613 |
CEmptyStruct2 e; |
| 1614 |
double b; |
| 1615 |
[[no_unique_address]] CEmptyStruct d; |
| 1616 |
}; |
| 1617 |
|
| 1618 |
union UnionLayout3 { |
| 1619 |
CStruct c; |
| 1620 |
int a; |
| 1621 |
double b; |
| 1622 |
[[no_unique_address]] CEmptyStruct d; |
| 1623 |
}; |
| 1624 |
|
| 1625 |
union UnionNoOveralignedMembers { |
| 1626 |
int a; |
| 1627 |
double b; |
| 1628 |
}; |
| 1629 |
|
| 1630 |
union UnionWithOveralignedMembers { |
| 1631 |
int a; |
| 1632 |
alignas(16) double b; |
| 1633 |
}; |
| 1634 |
|
| 1635 |
struct StructWithAnonUnion { |
| 1636 |
union { |
| 1637 |
int a; |
| 1638 |
double b; |
| 1639 |
CStruct c; |
| 1640 |
[[no_unique_address]] CEmptyStruct d; |
| 1641 |
[[no_unique_address]] CEmptyStruct2 e; |
| 1642 |
}; |
| 1643 |
}; |
| 1644 |
|
| 1645 |
struct StructWithAnonUnion2 { |
| 1646 |
union { |
| 1647 |
CStruct c; |
| 1648 |
int a; |
| 1649 |
CEmptyStruct2 e; |
| 1650 |
double b; |
| 1651 |
[[no_unique_address]] CEmptyStruct d; |
| 1652 |
}; |
| 1653 |
}; |
| 1654 |
|
| 1655 |
struct StructWithAnonUnion3 { |
| 1656 |
union { |
| 1657 |
CStruct c; |
| 1658 |
int a; |
| 1659 |
CEmptyStruct2 e; |
| 1660 |
double b; |
| 1661 |
[[no_unique_address]] CEmptyStruct d; |
| 1662 |
} u; |
| 1663 |
}; |
| 1664 |
|
| 1665 |
struct CStructWithArrayAtTheEnd { |
| 1666 |
int a; |
| 1667 |
int b[4]; |
| 1668 |
}; |
| 1669 |
|
| 1670 |
struct CStructWithFMA { |
| 1671 |
int c; |
| 1672 |
int d[]; |
| 1673 |
}; |
| 1674 |
|
| 1675 |
struct CStructWithFMA2 { |
| 1676 |
int e; |
| 1677 |
int f[]; |
| 1678 |
}; |
| 1679 |
|
| 1680 |
template<int N> |
| 1681 |
struct UniqueEmpty {}; |
| 1682 |
template<typename... Bases> |
| 1683 |
struct D : Bases... {}; |
| 1684 |
|
| 1685 |
void is_layout_compatible(int n) |
| 1686 |
{ |
| 1687 |
static_assert(__is_layout_compatible(void, void)); |
| 1688 |
static_assert(!__is_layout_compatible(void, int)); |
| 1689 |
static_assert(__is_layout_compatible(void, const void)); |
| 1690 |
static_assert(__is_layout_compatible(void, volatile void)); |
| 1691 |
static_assert(__is_layout_compatible(const void, volatile void)); |
| 1692 |
static_assert(__is_layout_compatible(int, int)); |
| 1693 |
static_assert(__is_layout_compatible(int, const int)); |
| 1694 |
static_assert(__is_layout_compatible(int, volatile int)); |
| 1695 |
static_assert(__is_layout_compatible(const int, volatile int)); |
| 1696 |
static_assert(__is_layout_compatible(int *, int * __restrict)); |
| 1697 |
// Note: atomic qualification matters for layout compatibility. |
| 1698 |
static_assert(!__is_layout_compatible(int, _Atomic int)); |
| 1699 |
static_assert(__is_layout_compatible(_Atomic(int), _Atomic int)); |
| 1700 |
static_assert(!__is_layout_compatible(int, unsigned int)); |
| 1701 |
static_assert(!__is_layout_compatible(char, unsigned char)); |
| 1702 |
static_assert(!__is_layout_compatible(char, signed char)); |
| 1703 |
static_assert(!__is_layout_compatible(unsigned char, signed char)); |
| 1704 |
static_assert(__is_layout_compatible(int[], int[])); |
| 1705 |
static_assert(__is_layout_compatible(int[2], int[2])); |
| 1706 |
static_assert(!__is_layout_compatible(int[n], int[2])); |
| 1707 |
// expected-error@-1 {{variable length arrays are not supported in '__is_layout_compatible'}} |
| 1708 |
static_assert(!__is_layout_compatible(int[n], int[n])); |
| 1709 |
// expected-error@-1 {{variable length arrays are not supported in '__is_layout_compatible'}} |
| 1710 |
// expected-error@-2 {{variable length arrays are not supported in '__is_layout_compatible'}} |
| 1711 |
static_assert(__is_layout_compatible(int&, int&)); |
| 1712 |
static_assert(!__is_layout_compatible(int&, char&)); |
| 1713 |
static_assert(__is_layout_compatible(void(int), void(int))); |
| 1714 |
static_assert(!__is_layout_compatible(void(int), void(char))); |
| 1715 |
static_assert(__is_layout_compatible(void(&)(int), void(&)(int))); |
| 1716 |
static_assert(!__is_layout_compatible(void(&)(int), void(&)(char))); |
| 1717 |
static_assert(__is_layout_compatible(void(*)(int), void(*)(int))); |
| 1718 |
static_assert(!__is_layout_compatible(void(*)(int), void(*)(char))); |
| 1719 |
using function_type = void(); |
| 1720 |
using function_type2 = void(char); |
| 1721 |
static_assert(__is_layout_compatible(const function_type, const function_type)); |
| 1722 |
// expected-warning@-1 {{'const' qualifier on function type 'function_type' (aka 'void ()') has no effect}} |
| 1723 |
// expected-warning@-2 {{'const' qualifier on function type 'function_type' (aka 'void ()') has no effect}} |
| 1724 |
static_assert(__is_layout_compatible(function_type, const function_type)); |
| 1725 |
// expected-warning@-1 {{'const' qualifier on function type 'function_type' (aka 'void ()') has no effect}} |
| 1726 |
static_assert(!__is_layout_compatible(const function_type, const function_type2)); |
| 1727 |
// expected-warning@-1 {{'const' qualifier on function type 'function_type' (aka 'void ()') has no effect}} |
| 1728 |
// expected-warning@-2 {{'const' qualifier on function type 'function_type2' (aka 'void (char)') has no effect}} |
| 1729 |
static_assert(__is_layout_compatible(CStruct, CStruct2)); |
| 1730 |
static_assert(__is_layout_compatible(CStruct, const CStruct2)); |
| 1731 |
static_assert(__is_layout_compatible(CStruct, volatile CStruct2)); |
| 1732 |
static_assert(__is_layout_compatible(const CStruct, volatile CStruct2)); |
| 1733 |
static_assert(__is_layout_compatible(CEmptyStruct, CEmptyStruct2)); |
| 1734 |
static_assert(__is_layout_compatible(CppEmptyStruct, CppEmptyStruct2)); |
| 1735 |
static_assert(__is_layout_compatible(CppStructStandard, CppStructStandard2)); |
| 1736 |
static_assert(!__is_layout_compatible(CppStructNonStandardByBase, CppStructNonStandardByBase2)); |
| 1737 |
static_assert(!__is_layout_compatible(CppStructNonStandardByVirt, CppStructNonStandardByVirt2)); |
| 1738 |
static_assert(!__is_layout_compatible(CppStructNonStandardByMemb, CppStructNonStandardByMemb2)); |
| 1739 |
static_assert(!__is_layout_compatible(CppStructNonStandardByProt, CppStructNonStandardByProt2)); |
| 1740 |
static_assert(!__is_layout_compatible(CppStructNonStandardByVirtBase, CppStructNonStandardByVirtBase2)); |
| 1741 |
static_assert(!__is_layout_compatible(CppStructNonStandardBySameBase, CppStructNonStandardBySameBase2)); |
| 1742 |
static_assert(!__is_layout_compatible(CppStructNonStandardBy2ndVirtBase, CppStructNonStandardBy2ndVirtBase2)); |
| 1743 |
static_assert(__is_layout_compatible(CStruct, CStructWithQualifiers)); |
| 1744 |
static_assert(__is_layout_compatible(CStruct, CStructNoUniqueAddress) != bool(__has_cpp_attribute(no_unique_address))); |
| 1745 |
static_assert(__is_layout_compatible(CStructNoUniqueAddress, CStructNoUniqueAddress2) != bool(__has_cpp_attribute(no_unique_address))); |
| 1746 |
static_assert(__is_layout_compatible(CStruct, CStructAlignment)); |
| 1747 |
static_assert(!__is_layout_compatible(CStruct, CStructAlignedMembers)); |
| 1748 |
static_assert(__is_layout_compatible(UnionNoOveralignedMembers, UnionWithOveralignedMembers)); |
| 1749 |
static_assert(__is_layout_compatible(CStructWithBitfelds, CStructWithBitfelds)); |
| 1750 |
static_assert(__is_layout_compatible(CStructWithBitfelds, CStructWithBitfelds2)); |
| 1751 |
static_assert(!__is_layout_compatible(CStructWithBitfelds, CStructWithBitfelds3)); |
| 1752 |
static_assert(!__is_layout_compatible(CStructWithBitfelds, CStructWithBitfelds4)); |
| 1753 |
static_assert(__is_layout_compatible(int CStruct2::*, int CStruct2::*)); |
| 1754 |
static_assert(!__is_layout_compatible(int CStruct2::*, char CStruct2::*)); |
| 1755 |
static_assert(__is_layout_compatible(void(CStruct2::*)(int), void(CStruct2::*)(int))); |
| 1756 |
static_assert(!__is_layout_compatible(void(CStruct2::*)(int), void(CStruct2::*)(char))); |
| 1757 |
static_assert(__is_layout_compatible(CStructNested, CStructNested2)); |
| 1758 |
static_assert(__is_layout_compatible(UnionLayout, UnionLayout)); |
| 1759 |
static_assert(!__is_layout_compatible(UnionLayout, UnionLayout2)); |
| 1760 |
static_assert(!__is_layout_compatible(UnionLayout, UnionLayout3)); |
| 1761 |
static_assert(!__is_layout_compatible(StructWithAnonUnion, StructWithAnonUnion2)); |
| 1762 |
static_assert(!__is_layout_compatible(StructWithAnonUnion, StructWithAnonUnion3)); |
| 1763 |
static_assert(__is_layout_compatible(EnumLayout, EnumClassLayout)); |
| 1764 |
static_assert(__is_layout_compatible(EnumForward, EnumForward)); |
| 1765 |
static_assert(__is_layout_compatible(EnumForward, EnumClassForward)); |
| 1766 |
static_assert(__is_layout_compatible(CStructIncomplete, CStructIncomplete)); |
| 1767 |
// expected-error@-1 {{incomplete type 'CStructIncomplete' where a complete type is required}} |
| 1768 |
// expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}} |
| 1769 |
// expected-error@-3 {{incomplete type 'CStructIncomplete' where a complete type is required}} |
| 1770 |
// expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}} |
| 1771 |
static_assert(!__is_layout_compatible(CStruct, CStructIncomplete)); |
| 1772 |
// expected-error@-1 {{incomplete type 'CStructIncomplete' where a complete type is required}} |
| 1773 |
// expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}} |
| 1774 |
static_assert(__is_layout_compatible(CStructIncomplete[2], CStructIncomplete[2])); |
| 1775 |
// expected-error@-1 {{incomplete type 'CStructIncomplete[2]' where a complete type is required}} |
| 1776 |
// expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}} |
| 1777 |
// expected-error@-3 {{incomplete type 'CStructIncomplete[2]' where a complete type is required}} |
| 1778 |
// expected-note@#CStructIncomplete {{forward declaration of 'CStructIncomplete'}} |
| 1779 |
static_assert(__is_layout_compatible(CStructIncomplete[], CStructIncomplete[])); |
| 1780 |
static_assert(!__is_layout_compatible(CStructWithArrayAtTheEnd, CStructWithFMA)); |
| 1781 |
static_assert(__is_layout_compatible(CStructWithFMA, CStructWithFMA)); |
| 1782 |
static_assert(__is_layout_compatible(CStructWithFMA, CStructWithFMA2)); |
| 1783 |
// Layout compatibility rules for enums might be relaxed in the future. See https://github.com/cplusplus/CWG/issues/39#issuecomment-1184791364 |
| 1784 |
static_assert(!__is_layout_compatible(EnumLayout, int)); |
| 1785 |
static_assert(!__is_layout_compatible(EnumClassLayout, int)); |
| 1786 |
static_assert(!__is_layout_compatible(EnumForward, int)); |
| 1787 |
static_assert(!__is_layout_compatible(EnumClassForward, int)); |
| 1788 |
static_assert(__is_layout_compatible(CStruct, D<CStruct>)); |
| 1789 |
static_assert(__is_layout_compatible(CStruct, D<UniqueEmpty<0>, CStruct>)); |
| 1790 |
static_assert(__is_layout_compatible(CStruct, D<UniqueEmpty<0>, D<UniqueEmpty<1>, CStruct>, D<UniqueEmpty<2>>>)); |
| 1791 |
static_assert(__is_layout_compatible(CStruct, D<CStructWithQualifiers>)); |
| 1792 |
static_assert(__is_layout_compatible(CStruct, D<UniqueEmpty<0>, CStructWithQualifiers>)); |
| 1793 |
static_assert(__is_layout_compatible(CStructWithQualifiers, D<UniqueEmpty<0>, D<UniqueEmpty<1>, CStruct>, D<UniqueEmpty<2>>>)); |
| 1794 |
} |
| 1795 |
|
| 1796 |
namespace IPIBO { |
| 1797 |
struct Base {}; |
| 1798 |
struct Base2 {}; |
| 1799 |
struct Base3 : Base {}; |
| 1800 |
struct Base3Virtual : virtual Base {}; |
| 1801 |
struct Derived : Base {}; |
| 1802 |
struct DerivedIndirect : Base3 {}; |
| 1803 |
struct DerivedMultiple : Base, Base2 {}; |
| 1804 |
struct DerivedAmbiguous : Base, Base3 {}; |
| 1805 |
/* expected-warning@-1 {{direct base 'Base' is inaccessible due to ambiguity: |
| 1806 |
struct IPIBO::DerivedAmbiguous -> Base |
| 1807 |
struct IPIBO::DerivedAmbiguous -> Base3 -> Base}} */ |
| 1808 |
struct DerivedPrivate : private Base {}; |
| 1809 |
struct DerivedVirtual : virtual Base {}; |
| 1810 |
|
| 1811 |
union Union {}; |
| 1812 |
union UnionIncomplete; |
| 1813 |
struct StructIncomplete; // #StructIncomplete |
| 1814 |
|
| 1815 |
#if __cplusplus >= 201402L |
| 1816 |
template<class _Base, class _Derived> |
| 1817 |
inline constexpr bool IsPointerInterconvertibleBaseOfV = __is_pointer_interconvertible_base_of(_Base, _Derived); |
| 1818 |
#endif |
| 1819 |
|
| 1820 |
void is_pointer_interconvertible_base_of(int n) |
| 1821 |
{ |
| 1822 |
static_assert(__is_pointer_interconvertible_base_of(Base, Derived)); |
| 1823 |
static_assert(!__is_pointer_interconvertible_base_of(Base2, Derived)); |
| 1824 |
static_assert(__is_pointer_interconvertible_base_of(Base, DerivedIndirect)); |
| 1825 |
static_assert(__is_pointer_interconvertible_base_of(Base, DerivedMultiple)); |
| 1826 |
static_assert(__is_pointer_interconvertible_base_of(Base2, DerivedMultiple)); |
| 1827 |
static_assert(!__is_pointer_interconvertible_base_of(Base3, DerivedMultiple)); |
| 1828 |
static_assert(!__is_pointer_interconvertible_base_of(Base, DerivedAmbiguous)); |
| 1829 |
static_assert(__is_pointer_interconvertible_base_of(Base, DerivedPrivate)); |
| 1830 |
static_assert(!__is_pointer_interconvertible_base_of(Base, DerivedVirtual)); |
| 1831 |
static_assert(!__is_pointer_interconvertible_base_of(Union, Union)); |
| 1832 |
static_assert(!__is_pointer_interconvertible_base_of(UnionIncomplete, UnionIncomplete)); |
| 1833 |
static_assert(__is_pointer_interconvertible_base_of(StructIncomplete, StructIncomplete)); |
| 1834 |
static_assert(__is_pointer_interconvertible_base_of(StructIncomplete, const StructIncomplete)); |
| 1835 |
static_assert(__is_pointer_interconvertible_base_of(StructIncomplete, volatile StructIncomplete)); |
| 1836 |
static_assert(__is_pointer_interconvertible_base_of(const StructIncomplete, volatile StructIncomplete)); |
| 1837 |
static_assert(!__is_pointer_interconvertible_base_of(StructIncomplete, Derived)); |
| 1838 |
static_assert(!__is_pointer_interconvertible_base_of(Base, StructIncomplete)); |
| 1839 |
// expected-error@-1 {{incomplete type 'StructIncomplete' where a complete type is required}} |
| 1840 |
// expected-note@#StructIncomplete {{forward declaration of 'IPIBO::StructIncomplete'}} |
| 1841 |
static_assert(!__is_pointer_interconvertible_base_of(CStruct2, CppStructNonStandardByBase2)); |
| 1842 |
static_assert(!__is_pointer_interconvertible_base_of(void, void)); |
| 1843 |
static_assert(!__is_pointer_interconvertible_base_of(void, int)); |
| 1844 |
static_assert(!__is_pointer_interconvertible_base_of(void, const void)); |
| 1845 |
static_assert(!__is_pointer_interconvertible_base_of(void, volatile void)); |
| 1846 |
static_assert(!__is_pointer_interconvertible_base_of(const void, volatile void)); |
| 1847 |
static_assert(!__is_pointer_interconvertible_base_of(int, int)); |
| 1848 |
static_assert(!__is_pointer_interconvertible_base_of(int, const int)); |
| 1849 |
static_assert(!__is_pointer_interconvertible_base_of(int, volatile int)); |
| 1850 |
static_assert(!__is_pointer_interconvertible_base_of(const int, volatile int)); |
| 1851 |
static_assert(!__is_pointer_interconvertible_base_of(int *, int * __restrict)); |
| 1852 |
static_assert(!__is_pointer_interconvertible_base_of(int, _Atomic int)); |
| 1853 |
static_assert(!__is_pointer_interconvertible_base_of(_Atomic(int), _Atomic int)); |
| 1854 |
static_assert(!__is_pointer_interconvertible_base_of(int, unsigned int)); |
| 1855 |
static_assert(!__is_pointer_interconvertible_base_of(char, unsigned char)); |
| 1856 |
static_assert(!__is_pointer_interconvertible_base_of(char, signed char)); |
| 1857 |
static_assert(!__is_pointer_interconvertible_base_of(unsigned char, signed char)); |
| 1858 |
using function_type = void(); |
| 1859 |
using function_type2 = void(char); |
| 1860 |
static_assert(!__is_pointer_interconvertible_base_of(const function_type, const function_type)); |
| 1861 |
// expected-warning@-1 {{'const' qualifier on function type 'function_type' (aka 'void ()') has no effect}} |
| 1862 |
// expected-warning@-2 {{'const' qualifier on function type 'function_type' (aka 'void ()') has no effect}} |
| 1863 |
static_assert(!__is_pointer_interconvertible_base_of(function_type, const function_type)); |
| 1864 |
// expected-warning@-1 {{'const' qualifier on function type 'function_type' (aka 'void ()') has no effect}} |
| 1865 |
static_assert(!__is_pointer_interconvertible_base_of(const function_type, const function_type2)); |
| 1866 |
// expected-warning@-1 {{'const' qualifier on function type 'function_type' (aka 'void ()') has no effect}} |
| 1867 |
// expected-warning@-2 {{'const' qualifier on function type 'function_type2' (aka 'void (char)') has no effect}} |
| 1868 |
static_assert(!__is_pointer_interconvertible_base_of(int CStruct2::*, int CStruct2::*)); |
| 1869 |
static_assert(!__is_pointer_interconvertible_base_of(int CStruct2::*, char CStruct2::*)); |
| 1870 |
static_assert(!__is_pointer_interconvertible_base_of(void(CStruct2::*)(int), void(CStruct2::*)(int))); |
| 1871 |
static_assert(!__is_pointer_interconvertible_base_of(void(CStruct2::*)(int), void(CStruct2::*)(char))); |
| 1872 |
static_assert(!__is_pointer_interconvertible_base_of(int[], int[])); |
| 1873 |
static_assert(!__is_pointer_interconvertible_base_of(int[], double[])); |
| 1874 |
static_assert(!__is_pointer_interconvertible_base_of(int[2], int[2])); |
| 1875 |
static_assert(!__is_pointer_interconvertible_base_of(int[n], int[2])); |
| 1876 |
// expected-error@-1 {{variable length arrays are not supported in '__is_pointer_interconvertible_base_of'}} |
| 1877 |
static_assert(!__is_pointer_interconvertible_base_of(int[n], int[n])); |
| 1878 |
// expected-error@-1 {{variable length arrays are not supported in '__is_pointer_interconvertible_base_of'}} |
| 1879 |
// expected-error@-2 {{variable length arrays are not supported in '__is_pointer_interconvertible_base_of'}} |
| 1880 |
static_assert(!__is_pointer_interconvertible_base_of(int&, int&)); |
| 1881 |
static_assert(!__is_pointer_interconvertible_base_of(int&, char&)); |
| 1882 |
static_assert(!__is_pointer_interconvertible_base_of(void(int), void(int))); |
| 1883 |
static_assert(!__is_pointer_interconvertible_base_of(void(int), void(char))); |
| 1884 |
static_assert(!__is_pointer_interconvertible_base_of(void(&)(int), void(&)(int))); |
| 1885 |
static_assert(!__is_pointer_interconvertible_base_of(void(&)(int), void(&)(char))); |
| 1886 |
static_assert(!__is_pointer_interconvertible_base_of(void(*)(int), void(*)(int))); |
| 1887 |
static_assert(!__is_pointer_interconvertible_base_of(void(*)(int), void(*)(char))); |
| 1888 |
|
| 1889 |
#if __cplusplus >= 201402L |
| 1890 |
static_assert(IsPointerInterconvertibleBaseOfV<const Base, Base>); |
| 1891 |
static_assert(IsPointerInterconvertibleBaseOfV<const Base, Derived>); |
| 1892 |
#endif |
| 1893 |
} |
| 1894 |
} |
| 1895 |
|
| 1896 |
struct NoEligibleTrivialContructor { |
| 1897 |
NoEligibleTrivialContructor() {}; |
| 1898 |
NoEligibleTrivialContructor(const NoEligibleTrivialContructor&) {} |
| 1899 |
NoEligibleTrivialContructor(NoEligibleTrivialContructor&&) {} |
| 1900 |
}; |
| 1901 |
|
| 1902 |
struct OnlyDefaultConstructorIsTrivial { |
| 1903 |
OnlyDefaultConstructorIsTrivial() = default; |
| 1904 |
OnlyDefaultConstructorIsTrivial(const OnlyDefaultConstructorIsTrivial&) {} |
| 1905 |
OnlyDefaultConstructorIsTrivial(OnlyDefaultConstructorIsTrivial&&) {} |
| 1906 |
}; |
| 1907 |
|
| 1908 |
struct AllContstructorsAreTrivial { |
| 1909 |
AllContstructorsAreTrivial() = default; |
| 1910 |
AllContstructorsAreTrivial(const AllContstructorsAreTrivial&) = default; |
| 1911 |
AllContstructorsAreTrivial(AllContstructorsAreTrivial&&) = default; |
| 1912 |
}; |
| 1913 |
|
| 1914 |
struct InheritedNoEligibleTrivialConstructor : NoEligibleTrivialContructor { |
| 1915 |
using NoEligibleTrivialContructor::NoEligibleTrivialContructor; |
| 1916 |
}; |
| 1917 |
|
| 1918 |
struct InheritedOnlyDefaultConstructorIsTrivial : OnlyDefaultConstructorIsTrivial { |
| 1919 |
using OnlyDefaultConstructorIsTrivial::OnlyDefaultConstructorIsTrivial; |
| 1920 |
}; |
| 1921 |
|
| 1922 |
struct InheritedAllContstructorsAreTrivial : AllContstructorsAreTrivial { |
| 1923 |
using AllContstructorsAreTrivial::AllContstructorsAreTrivial; |
| 1924 |
}; |
| 1925 |
|
| 1926 |
struct UserDeclaredDestructor { |
| 1927 |
~UserDeclaredDestructor() = default; |
| 1928 |
}; |
| 1929 |
|
| 1930 |
struct UserProvidedDestructor { |
| 1931 |
~UserProvidedDestructor() {} |
| 1932 |
}; |
| 1933 |
|
| 1934 |
struct UserDeletedDestructorInAggregate { |
| 1935 |
~UserDeletedDestructorInAggregate() = delete; |
| 1936 |
}; |
| 1937 |
|
| 1938 |
struct UserDeletedDestructorInNonAggregate { |
| 1939 |
virtual void NonAggregate(); |
| 1940 |
~UserDeletedDestructorInNonAggregate() = delete; |
| 1941 |
}; |
| 1942 |
|
| 1943 |
struct DeletedDestructorViaBaseInAggregate : UserDeletedDestructorInAggregate {}; |
| 1944 |
struct DeletedDestructorViaBaseInNonAggregate : UserDeletedDestructorInNonAggregate {}; |
| 1945 |
|
| 1946 |
#if __cplusplus >= 202002L |
| 1947 |
template<bool B> |
| 1948 |
struct ConstrainedUserDeclaredDefaultConstructor{ |
| 1949 |
ConstrainedUserDeclaredDefaultConstructor() requires B = default; |
| 1950 |
ConstrainedUserDeclaredDefaultConstructor(const ConstrainedUserDeclaredDefaultConstructor&) {} |
| 1951 |
}; |
| 1952 |
|
| 1953 |
template<bool B> |
| 1954 |
struct ConstrainedUserProvidedDestructor { |
| 1955 |
~ConstrainedUserProvidedDestructor() = default; |
| 1956 |
~ConstrainedUserProvidedDestructor() requires B {} |
| 1957 |
}; |
| 1958 |
#endif |
| 1959 |
|
| 1960 |
struct StructWithFAM { |
| 1961 |
int a[]; |
| 1962 |
}; |
| 1963 |
|
| 1964 |
struct StructWithZeroSizedArray { |
| 1965 |
int a[0]; |
| 1966 |
}; |
| 1967 |
|
| 1968 |
typedef float float4 __attribute__((ext_vector_type(4))); |
| 1969 |
typedef int *align_value_int __attribute__((align_value(16))); |
| 1970 |
|
| 1971 |
struct [[clang::enforce_read_only_placement]] EnforceReadOnlyPlacement {}; |
| 1972 |
struct [[clang::type_visibility("hidden")]] TypeVisibility {}; |
| 1973 |
|
| 1974 |
void is_implicit_lifetime(int n) { |
| 1975 |
static_assert(__builtin_is_implicit_lifetime(decltype(nullptr))); |
| 1976 |
static_assert(!__builtin_is_implicit_lifetime(void)); |
| 1977 |
static_assert(!__builtin_is_implicit_lifetime(const void)); |
| 1978 |
static_assert(!__builtin_is_implicit_lifetime(volatile void)); |
| 1979 |
static_assert(__builtin_is_implicit_lifetime(int)); |
| 1980 |
static_assert(!__builtin_is_implicit_lifetime(int&)); |
| 1981 |
static_assert(!__builtin_is_implicit_lifetime(int&&)); |
| 1982 |
static_assert(__builtin_is_implicit_lifetime(float)); |
| 1983 |
static_assert(__builtin_is_implicit_lifetime(double)); |
| 1984 |
static_assert(__builtin_is_implicit_lifetime(long double)); |
| 1985 |
static_assert(__builtin_is_implicit_lifetime(int*)); |
| 1986 |
static_assert(__builtin_is_implicit_lifetime(int[])); |
| 1987 |
static_assert(__builtin_is_implicit_lifetime(int[5])); |
| 1988 |
static_assert(__builtin_is_implicit_lifetime(int[n])); |
| 1989 |
// expected-error@-1 {{variable length arrays are not supported in '__builtin_is_implicit_lifetime'}} |
| 1990 |
static_assert(__builtin_is_implicit_lifetime(Enum)); |
| 1991 |
static_assert(__builtin_is_implicit_lifetime(EnumClass)); |
| 1992 |
static_assert(!__builtin_is_implicit_lifetime(void())); |
| 1993 |
static_assert(!__builtin_is_implicit_lifetime(void() &)); |
| 1994 |
static_assert(!__builtin_is_implicit_lifetime(void() const)); |
| 1995 |
static_assert(!__builtin_is_implicit_lifetime(void(&)())); |
| 1996 |
static_assert(__builtin_is_implicit_lifetime(void(*)())); |
| 1997 |
static_assert(__builtin_is_implicit_lifetime(decltype(nullptr))); |
| 1998 |
static_assert(__builtin_is_implicit_lifetime(int UserDeclaredDestructor::*)); |
| 1999 |
static_assert(__builtin_is_implicit_lifetime(int (UserDeclaredDestructor::*)())); |
| 2000 |
static_assert(__builtin_is_implicit_lifetime(int (UserDeclaredDestructor::*)() const)); |
| 2001 |
static_assert(__builtin_is_implicit_lifetime(int (UserDeclaredDestructor::*)() &)); |
| 2002 |
static_assert(__builtin_is_implicit_lifetime(int (UserDeclaredDestructor::*)() &&)); |
| 2003 |
static_assert(!__builtin_is_implicit_lifetime(IncompleteStruct)); |
| 2004 |
// expected-error@-1 {{incomplete type 'IncompleteStruct' used in type trait expression}} |
| 2005 |
static_assert(__builtin_is_implicit_lifetime(IncompleteStruct[])); |
| 2006 |
static_assert(__builtin_is_implicit_lifetime(IncompleteStruct[5])); |
| 2007 |
static_assert(__builtin_is_implicit_lifetime(UserDeclaredDestructor)); |
| 2008 |
static_assert(__builtin_is_implicit_lifetime(const UserDeclaredDestructor)); |
| 2009 |
static_assert(__builtin_is_implicit_lifetime(volatile UserDeclaredDestructor)); |
| 2010 |
static_assert(!__builtin_is_implicit_lifetime(UserProvidedDestructor)); |
| 2011 |
static_assert(!__builtin_is_implicit_lifetime(NoEligibleTrivialContructor)); |
| 2012 |
static_assert(__builtin_is_implicit_lifetime(OnlyDefaultConstructorIsTrivial)); |
| 2013 |
static_assert(__builtin_is_implicit_lifetime(AllContstructorsAreTrivial)); |
| 2014 |
static_assert(!__builtin_is_implicit_lifetime(InheritedNoEligibleTrivialConstructor)); |
| 2015 |
static_assert(__builtin_is_implicit_lifetime(InheritedOnlyDefaultConstructorIsTrivial)); |
| 2016 |
static_assert(__builtin_is_implicit_lifetime(InheritedAllContstructorsAreTrivial)); |
| 2017 |
static_assert(__builtin_is_implicit_lifetime(UserDeletedDestructorInAggregate)); |
| 2018 |
static_assert(!__builtin_is_implicit_lifetime(UserDeletedDestructorInNonAggregate)); |
| 2019 |
static_assert(__builtin_is_implicit_lifetime(DeletedDestructorViaBaseInAggregate) == __cplusplus >= 201703L); |
| 2020 |
static_assert(!__builtin_is_implicit_lifetime(DeletedDestructorViaBaseInNonAggregate)); |
| 2021 |
#if __cplusplus >= 202002L |
| 2022 |
static_assert(__builtin_is_implicit_lifetime(ConstrainedUserDeclaredDefaultConstructor<true>)); |
| 2023 |
static_assert(!__builtin_is_implicit_lifetime(ConstrainedUserDeclaredDefaultConstructor<false>)); |
| 2024 |
static_assert(!__builtin_is_implicit_lifetime(ConstrainedUserProvidedDestructor<true>)); |
| 2025 |
static_assert(__builtin_is_implicit_lifetime(ConstrainedUserProvidedDestructor<false>)); |
| 2026 |
#endif |
| 2027 |
|
| 2028 |
static_assert(__builtin_is_implicit_lifetime(__int128)); |
| 2029 |
static_assert(__builtin_is_implicit_lifetime(_BitInt(8))); |
| 2030 |
static_assert(__builtin_is_implicit_lifetime(_BitInt(128))); |
| 2031 |
static_assert(__builtin_is_implicit_lifetime(int[0])); |
| 2032 |
static_assert(__builtin_is_implicit_lifetime(StructWithFAM)); |
| 2033 |
static_assert(__builtin_is_implicit_lifetime(StructWithZeroSizedArray)); |
| 2034 |
static_assert(__builtin_is_implicit_lifetime(__fp16)); |
| 2035 |
static_assert(__builtin_is_implicit_lifetime(__bf16)); |
| 2036 |
static_assert(__builtin_is_implicit_lifetime(_Complex double)); |
| 2037 |
static_assert(__builtin_is_implicit_lifetime(float4)); |
| 2038 |
static_assert(__builtin_is_implicit_lifetime(align_value_int)); |
| 2039 |
static_assert(__builtin_is_implicit_lifetime(int[[clang::annotate_type("category2")]] *)); |
| 2040 |
static_assert(__builtin_is_implicit_lifetime(EnforceReadOnlyPlacement)); |
| 2041 |
static_assert(__builtin_is_implicit_lifetime(int __attribute__((noderef)) *)); |
| 2042 |
static_assert(__builtin_is_implicit_lifetime(TypeVisibility)); |
| 2043 |
static_assert(__builtin_is_implicit_lifetime(int * _Nonnull)); |
| 2044 |
static_assert(__builtin_is_implicit_lifetime(int * _Null_unspecified)); |
| 2045 |
static_assert(__builtin_is_implicit_lifetime(int * _Nullable)); |
| 2046 |
static_assert(!__builtin_is_implicit_lifetime(_Atomic int)); |
| 2047 |
// expected-error@-1 {{atomic types are not supported in '__builtin_is_implicit_lifetime'}} |
| 2048 |
static_assert(__builtin_is_implicit_lifetime(int * __restrict)); |
| 2049 |
} |
| 2050 |
|
| 2051 |
namespace GH160610 { |
| 2052 |
class NonAggregate { |
| 2053 |
public: |
| 2054 |
NonAggregate() = default; |
| 2055 |
|
| 2056 |
NonAggregate(const NonAggregate&) = delete; |
| 2057 |
NonAggregate& operator=(const NonAggregate&) = delete; |
| 2058 |
private: |
| 2059 |
int num; |
| 2060 |
}; |
| 2061 |
|
| 2062 |
class DataMemberInitializer { |
| 2063 |
public: |
| 2064 |
DataMemberInitializer() = default; |
| 2065 |
|
| 2066 |
DataMemberInitializer(const DataMemberInitializer&) = delete; |
| 2067 |
DataMemberInitializer& operator=(const DataMemberInitializer&) = delete; |
| 2068 |
private: |
| 2069 |
int num = 0; |
| 2070 |
}; |
| 2071 |
|
| 2072 |
class UserProvidedConstructor { |
| 2073 |
public: |
| 2074 |
UserProvidedConstructor() {} |
| 2075 |
|
| 2076 |
UserProvidedConstructor(const UserProvidedConstructor&) = delete; |
| 2077 |
UserProvidedConstructor& operator=(const UserProvidedConstructor&) = delete; |
| 2078 |
}; |
| 2079 |
struct Ctr { |
| 2080 |
Ctr(); |
| 2081 |
}; |
| 2082 |
struct Ctr2 { |
| 2083 |
Ctr2(); |
| 2084 |
private: |
| 2085 |
NoEligibleTrivialContructor inner; |
| 2086 |
}; |
| 2087 |
|
| 2088 |
struct NonCopyable{ |
| 2089 |
NonCopyable() = default; |
| 2090 |
NonCopyable(const NonCopyable&) = delete; |
| 2091 |
}; |
| 2092 |
|
| 2093 |
class C { |
| 2094 |
NonCopyable nc; |
| 2095 |
}; |
| 2096 |
|
| 2097 |
static_assert(__builtin_is_implicit_lifetime(Ctr)); |
| 2098 |
static_assert(!__builtin_is_implicit_lifetime(Ctr2)); |
| 2099 |
static_assert(__builtin_is_implicit_lifetime(C)); |
| 2100 |
static_assert(!__builtin_is_implicit_lifetime(NoEligibleTrivialContructor)); |
| 2101 |
static_assert(__builtin_is_implicit_lifetime(NonAggregate)); |
| 2102 |
static_assert(!__builtin_is_implicit_lifetime(DataMemberInitializer)); |
| 2103 |
static_assert(!__builtin_is_implicit_lifetime(UserProvidedConstructor)); |
| 2104 |
|
| 2105 |
#if __cplusplus >= 202002L |
| 2106 |
template <typename T> |
| 2107 |
class Tpl { |
| 2108 |
Tpl() requires false = default ; |
| 2109 |
}; |
| 2110 |
static_assert(__builtin_is_implicit_lifetime(Tpl<int>)); |
| 2111 |
|
| 2112 |
template <typename> |
| 2113 |
class MultipleDefaults { |
| 2114 |
MultipleDefaults() {}; |
| 2115 |
MultipleDefaults() requires true = default; |
| 2116 |
}; |
| 2117 |
static_assert(__builtin_is_implicit_lifetime(MultipleDefaults<int>)); |
| 2118 |
template <typename> |
| 2119 |
class MultipleDefaults2 { |
| 2120 |
MultipleDefaults2() requires true {}; |
| 2121 |
MultipleDefaults2() = default; |
| 2122 |
}; |
| 2123 |
|
| 2124 |
static_assert(__builtin_is_implicit_lifetime(MultipleDefaults2<int>)); |
| 2125 |
|
| 2126 |
|
| 2127 |
#endif |
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
} |
| 2132 |
|
| 2133 |
void is_signed() |
| 2134 |
{ |
| 2135 |
//static_assert(__is_signed(char)); |
| 2136 |
static_assert(__is_signed(int)); |
| 2137 |
static_assert(__is_signed(long)); |
| 2138 |
static_assert(__is_signed(short)); |
| 2139 |
static_assert(__is_signed(signed char)); |
| 2140 |
static_assert(__is_signed(wchar_t)); |
| 2141 |
static_assert(__is_signed(float)); |
| 2142 |
static_assert(__is_signed(double)); |
| 2143 |
static_assert(__is_signed(long double)); |
| 2144 |
|
| 2145 |
static_assert(!__is_signed(bool)); |
| 2146 |
static_assert(!__is_signed(cvoid)); |
| 2147 |
static_assert(!__is_signed(unsigned char)); |
| 2148 |
static_assert(!__is_signed(unsigned int)); |
| 2149 |
static_assert(!__is_signed(unsigned long long)); |
| 2150 |
static_assert(!__is_signed(unsigned long)); |
| 2151 |
static_assert(!__is_signed(unsigned short)); |
| 2152 |
static_assert(!__is_signed(void)); |
| 2153 |
static_assert(!__is_signed(ClassType)); |
| 2154 |
static_assert(!__is_signed(Derives)); |
| 2155 |
static_assert(!__is_signed(Enum)); |
| 2156 |
static_assert(!__is_signed(SignedEnum)); |
| 2157 |
static_assert(!__is_signed(IntArNB)); |
| 2158 |
static_assert(!__is_signed(Union)); |
| 2159 |
static_assert(!__is_signed(UnionAr)); |
| 2160 |
static_assert(!__is_signed(UnsignedEnum)); |
| 2161 |
} |
| 2162 |
|
| 2163 |
void is_unsigned() |
| 2164 |
{ |
| 2165 |
static_assert(__is_unsigned(bool)); |
| 2166 |
static_assert(__is_unsigned(unsigned char)); |
| 2167 |
static_assert(__is_unsigned(unsigned short)); |
| 2168 |
static_assert(__is_unsigned(unsigned int)); |
| 2169 |
static_assert(__is_unsigned(unsigned long)); |
| 2170 |
static_assert(__is_unsigned(unsigned long long)); |
| 2171 |
|
| 2172 |
static_assert(!__is_unsigned(void)); |
| 2173 |
static_assert(!__is_unsigned(cvoid)); |
| 2174 |
static_assert(!__is_unsigned(float)); |
| 2175 |
static_assert(!__is_unsigned(double)); |
| 2176 |
static_assert(!__is_unsigned(long double)); |
| 2177 |
static_assert(!__is_unsigned(char)); |
| 2178 |
static_assert(!__is_unsigned(signed char)); |
| 2179 |
static_assert(!__is_unsigned(wchar_t)); |
| 2180 |
static_assert(!__is_unsigned(short)); |
| 2181 |
static_assert(!__is_unsigned(int)); |
| 2182 |
static_assert(!__is_unsigned(long)); |
| 2183 |
static_assert(!__is_unsigned(Union)); |
| 2184 |
static_assert(!__is_unsigned(UnionAr)); |
| 2185 |
static_assert(!__is_unsigned(Derives)); |
| 2186 |
static_assert(!__is_unsigned(ClassType)); |
| 2187 |
static_assert(!__is_unsigned(IntArNB)); |
| 2188 |
static_assert(!__is_unsigned(Enum)); |
| 2189 |
static_assert(!__is_unsigned(UnsignedEnum)); |
| 2190 |
static_assert(!__is_unsigned(SignedEnum)); |
| 2191 |
} |
| 2192 |
|
| 2193 |
typedef Int& IntRef; |
| 2194 |
typedef const IntAr ConstIntAr; |
| 2195 |
typedef ConstIntAr ConstIntArAr[4]; |
| 2196 |
|
| 2197 |
struct HasCopy { |
| 2198 |
HasCopy(HasCopy& cp); |
| 2199 |
}; |
| 2200 |
|
| 2201 |
struct HasMove { |
| 2202 |
HasMove(HasMove&& cp); |
| 2203 |
}; |
| 2204 |
|
| 2205 |
struct HasTemplateCons { |
| 2206 |
HasVirt Annoying; |
| 2207 |
|
| 2208 |
template <typename T> |
| 2209 |
HasTemplateCons(const T&); |
| 2210 |
}; |
| 2211 |
|
| 2212 |
void has_trivial_default_constructor() { |
| 2213 |
static_assert(__has_trivial_constructor(Int)); |
| 2214 |
static_assert(__has_trivial_constructor(IntAr)); |
| 2215 |
static_assert(__has_trivial_constructor(Union)); |
| 2216 |
static_assert(__has_trivial_constructor(UnionAr)); |
| 2217 |
static_assert(__has_trivial_constructor(POD)); |
| 2218 |
static_assert(__has_trivial_constructor(Derives)); |
| 2219 |
static_assert(__has_trivial_constructor(DerivesAr)); |
| 2220 |
static_assert(__has_trivial_constructor(ConstIntAr)); |
| 2221 |
static_assert(__has_trivial_constructor(ConstIntArAr)); |
| 2222 |
static_assert(__has_trivial_constructor(HasDest)); |
| 2223 |
static_assert(__has_trivial_constructor(HasPriv)); |
| 2224 |
static_assert(__has_trivial_constructor(HasCopyAssign)); |
| 2225 |
static_assert(__has_trivial_constructor(HasMoveAssign)); |
| 2226 |
static_assert(__has_trivial_constructor(const Int)); |
| 2227 |
static_assert(__has_trivial_constructor(AllDefaulted)); |
| 2228 |
static_assert(__has_trivial_constructor(AllDeleted)); |
| 2229 |
static_assert(__has_trivial_constructor(ACompleteType[])); |
| 2230 |
|
| 2231 |
static_assert(!__has_trivial_constructor(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2232 |
static_assert(!__has_trivial_constructor(HasCons)); |
| 2233 |
static_assert(!__has_trivial_constructor(HasRef)); |
| 2234 |
static_assert(!__has_trivial_constructor(HasCopy)); |
| 2235 |
static_assert(!__has_trivial_constructor(IntRef)); |
| 2236 |
static_assert(!__has_trivial_constructor(VirtAr)); |
| 2237 |
static_assert(!__has_trivial_constructor(void)); |
| 2238 |
static_assert(!__has_trivial_constructor(cvoid)); |
| 2239 |
static_assert(!__has_trivial_constructor(HasTemplateCons)); |
| 2240 |
static_assert(!__has_trivial_constructor(AllPrivate)); |
| 2241 |
static_assert(!__has_trivial_constructor(ExtDefaulted)); |
| 2242 |
} |
| 2243 |
|
| 2244 |
void has_trivial_move_constructor() { |
| 2245 |
// n3376 12.8 [class.copy]/12 |
| 2246 |
// A copy/move constructor for class X is trivial if it is not |
| 2247 |
// user-provided, its declared parameter type is the same as |
| 2248 |
// if it had been implicitly declared, and if |
| 2249 |
// - class X has no virtual functions (10.3) and no virtual |
| 2250 |
// base classes (10.1), and |
| 2251 |
// - the constructor selected to copy/move each direct base |
| 2252 |
// class subobject is trivial, and |
| 2253 |
// - for each non-static data member of X that is of class |
| 2254 |
// type (or array thereof), the constructor selected |
| 2255 |
// to copy/move that member is trivial; |
| 2256 |
// otherwise the copy/move constructor is non-trivial. |
| 2257 |
static_assert(__has_trivial_move_constructor(POD)); |
| 2258 |
static_assert(__has_trivial_move_constructor(Union)); |
| 2259 |
static_assert(__has_trivial_move_constructor(HasCons)); |
| 2260 |
static_assert(__has_trivial_move_constructor(HasStaticMemberMoveCtor)); |
| 2261 |
static_assert(__has_trivial_move_constructor(AllDeleted)); |
| 2262 |
static_assert(__has_trivial_move_constructor(ACompleteType[])); |
| 2263 |
|
| 2264 |
static_assert(!__has_trivial_move_constructor(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2265 |
static_assert(!__has_trivial_move_constructor(HasVirt)); |
| 2266 |
static_assert(!__has_trivial_move_constructor(DerivesVirt)); |
| 2267 |
static_assert(!__has_trivial_move_constructor(HasMoveCtor)); |
| 2268 |
static_assert(!__has_trivial_move_constructor(DerivesHasMoveCtor)); |
| 2269 |
static_assert(!__has_trivial_move_constructor(HasMemberMoveCtor)); |
| 2270 |
} |
| 2271 |
|
| 2272 |
void has_trivial_copy_constructor() { |
| 2273 |
static_assert(__has_trivial_copy(Int)); |
| 2274 |
static_assert(__has_trivial_copy(IntAr)); |
| 2275 |
static_assert(__has_trivial_copy(Union)); |
| 2276 |
static_assert(__has_trivial_copy(UnionAr)); |
| 2277 |
static_assert(__has_trivial_copy(POD)); |
| 2278 |
static_assert(__has_trivial_copy(Derives)); |
| 2279 |
static_assert(__has_trivial_copy(ConstIntAr)); |
| 2280 |
static_assert(__has_trivial_copy(ConstIntArAr)); |
| 2281 |
static_assert(__has_trivial_copy(HasDest)); |
| 2282 |
static_assert(__has_trivial_copy(HasPriv)); |
| 2283 |
static_assert(__has_trivial_copy(HasCons)); |
| 2284 |
static_assert(__has_trivial_copy(HasRef)); |
| 2285 |
static_assert(__has_trivial_copy(HasMove)); |
| 2286 |
static_assert(__has_trivial_copy(IntRef)); |
| 2287 |
static_assert(__has_trivial_copy(HasCopyAssign)); |
| 2288 |
static_assert(__has_trivial_copy(HasMoveAssign)); |
| 2289 |
static_assert(__has_trivial_copy(const Int)); |
| 2290 |
static_assert(__has_trivial_copy(AllDefaulted)); |
| 2291 |
static_assert(__has_trivial_copy(AllDeleted)); |
| 2292 |
static_assert(__has_trivial_copy(DerivesAr)); |
| 2293 |
static_assert(__has_trivial_copy(DerivesHasRef)); |
| 2294 |
static_assert(__has_trivial_copy(ACompleteType[])); |
| 2295 |
|
| 2296 |
static_assert(!__has_trivial_copy(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2297 |
static_assert(!__has_trivial_copy(HasCopy)); |
| 2298 |
static_assert(!__has_trivial_copy(HasTemplateCons)); |
| 2299 |
static_assert(!__has_trivial_copy(VirtAr)); |
| 2300 |
static_assert(!__has_trivial_copy(void)); |
| 2301 |
static_assert(!__has_trivial_copy(cvoid)); |
| 2302 |
static_assert(!__has_trivial_copy(AllPrivate)); |
| 2303 |
static_assert(!__has_trivial_copy(ExtDefaulted)); |
| 2304 |
} |
| 2305 |
|
| 2306 |
void has_trivial_copy_assignment() { |
| 2307 |
static_assert(__has_trivial_assign(Int)); |
| 2308 |
static_assert(__has_trivial_assign(IntAr)); |
| 2309 |
static_assert(__has_trivial_assign(Union)); |
| 2310 |
static_assert(__has_trivial_assign(UnionAr)); |
| 2311 |
static_assert(__has_trivial_assign(POD)); |
| 2312 |
static_assert(__has_trivial_assign(Derives)); |
| 2313 |
static_assert(__has_trivial_assign(HasDest)); |
| 2314 |
static_assert(__has_trivial_assign(HasPriv)); |
| 2315 |
static_assert(__has_trivial_assign(HasCons)); |
| 2316 |
static_assert(__has_trivial_assign(HasRef)); |
| 2317 |
static_assert(__has_trivial_assign(HasCopy)); |
| 2318 |
static_assert(__has_trivial_assign(HasMove)); |
| 2319 |
static_assert(__has_trivial_assign(HasMoveAssign)); |
| 2320 |
static_assert(__has_trivial_assign(AllDefaulted)); |
| 2321 |
static_assert(__has_trivial_assign(AllDeleted)); |
| 2322 |
static_assert(__has_trivial_assign(DerivesAr)); |
| 2323 |
static_assert(__has_trivial_assign(DerivesHasRef)); |
| 2324 |
static_assert(__has_trivial_assign(ACompleteType[])); |
| 2325 |
|
| 2326 |
static_assert(!__has_trivial_assign(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2327 |
static_assert(!__has_trivial_assign(IntRef)); |
| 2328 |
static_assert(!__has_trivial_assign(HasCopyAssign)); |
| 2329 |
static_assert(!__has_trivial_assign(const Int)); |
| 2330 |
static_assert(!__has_trivial_assign(ConstIntAr)); |
| 2331 |
static_assert(!__has_trivial_assign(ConstIntArAr)); |
| 2332 |
static_assert(!__has_trivial_assign(VirtAr)); |
| 2333 |
static_assert(!__has_trivial_assign(void)); |
| 2334 |
static_assert(!__has_trivial_assign(cvoid)); |
| 2335 |
static_assert(!__has_trivial_assign(AllPrivate)); |
| 2336 |
static_assert(!__has_trivial_assign(ExtDefaulted)); |
| 2337 |
} |
| 2338 |
|
| 2339 |
void has_trivial_destructor() { |
| 2340 |
static_assert(__has_trivial_destructor(Int)); |
| 2341 |
static_assert(__has_trivial_destructor(IntAr)); |
| 2342 |
static_assert(__has_trivial_destructor(Union)); |
| 2343 |
static_assert(__has_trivial_destructor(UnionAr)); |
| 2344 |
static_assert(__has_trivial_destructor(POD)); |
| 2345 |
static_assert(__has_trivial_destructor(Derives)); |
| 2346 |
static_assert(__has_trivial_destructor(ConstIntAr)); |
| 2347 |
static_assert(__has_trivial_destructor(ConstIntArAr)); |
| 2348 |
static_assert(__has_trivial_destructor(HasPriv)); |
| 2349 |
static_assert(__has_trivial_destructor(HasCons)); |
| 2350 |
static_assert(__has_trivial_destructor(HasRef)); |
| 2351 |
static_assert(__has_trivial_destructor(HasCopy)); |
| 2352 |
static_assert(__has_trivial_destructor(HasMove)); |
| 2353 |
static_assert(__has_trivial_destructor(IntRef)); |
| 2354 |
static_assert(__has_trivial_destructor(HasCopyAssign)); |
| 2355 |
static_assert(__has_trivial_destructor(HasMoveAssign)); |
| 2356 |
static_assert(__has_trivial_destructor(const Int)); |
| 2357 |
static_assert(__has_trivial_destructor(DerivesAr)); |
| 2358 |
static_assert(__has_trivial_destructor(VirtAr)); |
| 2359 |
static_assert(__has_trivial_destructor(AllDefaulted)); |
| 2360 |
static_assert(__has_trivial_destructor(AllDeleted)); |
| 2361 |
static_assert(__has_trivial_destructor(DerivesHasRef)); |
| 2362 |
static_assert(__has_trivial_destructor(ACompleteType[])); |
| 2363 |
|
| 2364 |
static_assert(!__has_trivial_destructor(HasDest)); |
| 2365 |
static_assert(!__has_trivial_destructor(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2366 |
static_assert(!__has_trivial_destructor(void)); |
| 2367 |
static_assert(!__has_trivial_destructor(cvoid)); |
| 2368 |
static_assert(!__has_trivial_destructor(AllPrivate)); |
| 2369 |
static_assert(!__has_trivial_destructor(ExtDefaulted)); |
| 2370 |
} |
| 2371 |
|
| 2372 |
struct A { ~A() {} }; |
| 2373 |
template<typename> struct B : A { }; |
| 2374 |
|
| 2375 |
void f() { |
| 2376 |
static_assert(!__has_trivial_destructor(A)); |
| 2377 |
static_assert(!__has_trivial_destructor(B<int>)); |
| 2378 |
} |
| 2379 |
|
| 2380 |
class PR11110 { |
| 2381 |
template <int> int operator=( int ); |
| 2382 |
int operator=(PR11110); |
| 2383 |
}; |
| 2384 |
|
| 2385 |
class UsingAssign; |
| 2386 |
|
| 2387 |
class UsingAssignBase { |
| 2388 |
protected: |
| 2389 |
UsingAssign &operator=(const UsingAssign&) throw(); |
| 2390 |
}; |
| 2391 |
|
| 2392 |
class UsingAssign : public UsingAssignBase { |
| 2393 |
public: |
| 2394 |
using UsingAssignBase::operator=; |
| 2395 |
}; |
| 2396 |
|
| 2397 |
void has_nothrow_assign() { |
| 2398 |
static_assert(__has_nothrow_assign(Int)); |
| 2399 |
static_assert(__has_nothrow_assign(IntAr)); |
| 2400 |
static_assert(__has_nothrow_assign(Union)); |
| 2401 |
static_assert(__has_nothrow_assign(UnionAr)); |
| 2402 |
static_assert(__has_nothrow_assign(POD)); |
| 2403 |
static_assert(__has_nothrow_assign(Derives)); |
| 2404 |
static_assert(__has_nothrow_assign(HasDest)); |
| 2405 |
static_assert(__has_nothrow_assign(HasPriv)); |
| 2406 |
static_assert(__has_nothrow_assign(HasCons)); |
| 2407 |
static_assert(__has_nothrow_assign(HasRef)); |
| 2408 |
static_assert(__has_nothrow_assign(HasCopy)); |
| 2409 |
static_assert(__has_nothrow_assign(HasMove)); |
| 2410 |
static_assert(__has_nothrow_assign(HasMoveAssign)); |
| 2411 |
static_assert(__has_nothrow_assign(HasNoThrowCopyAssign)); |
| 2412 |
static_assert(__has_nothrow_assign(HasMultipleNoThrowCopyAssign)); |
| 2413 |
static_assert(__has_nothrow_assign(HasVirtDest)); |
| 2414 |
static_assert(__has_nothrow_assign(AllPrivate)); |
| 2415 |
static_assert(__has_nothrow_assign(UsingAssign)); |
| 2416 |
static_assert(__has_nothrow_assign(DerivesAr)); |
| 2417 |
static_assert(__has_nothrow_assign(ACompleteType[])); |
| 2418 |
|
| 2419 |
static_assert(!__has_nothrow_assign(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2420 |
static_assert(!__has_nothrow_assign(IntRef)); |
| 2421 |
static_assert(!__has_nothrow_assign(HasCopyAssign)); |
| 2422 |
static_assert(!__has_nothrow_assign(HasMultipleCopyAssign)); |
| 2423 |
static_assert(!__has_nothrow_assign(const Int)); |
| 2424 |
static_assert(!__has_nothrow_assign(ConstIntAr)); |
| 2425 |
static_assert(!__has_nothrow_assign(ConstIntArAr)); |
| 2426 |
static_assert(!__has_nothrow_assign(VirtAr)); |
| 2427 |
static_assert(!__has_nothrow_assign(void)); |
| 2428 |
static_assert(!__has_nothrow_assign(cvoid)); |
| 2429 |
static_assert(!__has_nothrow_assign(PR11110)); |
| 2430 |
} |
| 2431 |
|
| 2432 |
void has_nothrow_move_assign() { |
| 2433 |
static_assert(__has_nothrow_move_assign(Int)); |
| 2434 |
static_assert(__has_nothrow_move_assign(Enum)); |
| 2435 |
static_assert(__has_nothrow_move_assign(Int*)); |
| 2436 |
static_assert(__has_nothrow_move_assign(Enum POD::*)); |
| 2437 |
static_assert(__has_nothrow_move_assign(POD)); |
| 2438 |
static_assert(__has_nothrow_move_assign(HasPriv)); |
| 2439 |
static_assert(__has_nothrow_move_assign(HasNoThrowMoveAssign)); |
| 2440 |
static_assert(__has_nothrow_move_assign(HasNoExceptNoThrowMoveAssign)); |
| 2441 |
static_assert(__has_nothrow_move_assign(HasMemberNoThrowMoveAssign)); |
| 2442 |
static_assert(__has_nothrow_move_assign(HasMemberNoExceptNoThrowMoveAssign)); |
| 2443 |
static_assert(__has_nothrow_move_assign(AllDeleted)); |
| 2444 |
static_assert(__has_nothrow_move_assign(ACompleteType[])); |
| 2445 |
|
| 2446 |
static_assert(!__has_nothrow_move_assign(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2447 |
static_assert(!__has_nothrow_move_assign(HasThrowMoveAssign)); |
| 2448 |
static_assert(!__has_nothrow_move_assign(HasNoExceptFalseMoveAssign)); |
| 2449 |
static_assert(!__has_nothrow_move_assign(HasMemberThrowMoveAssign)); |
| 2450 |
static_assert(!__has_nothrow_move_assign(HasMemberNoExceptFalseMoveAssign)); |
| 2451 |
static_assert(!__has_nothrow_move_assign(NoDefaultMoveAssignDueToUDCopyCtor)); |
| 2452 |
static_assert(!__has_nothrow_move_assign(NoDefaultMoveAssignDueToUDCopyAssign)); |
| 2453 |
static_assert(!__has_nothrow_move_assign(NoDefaultMoveAssignDueToDtor)); |
| 2454 |
|
| 2455 |
|
| 2456 |
static_assert(__is_nothrow_assignable(HasNoThrowMoveAssign, HasNoThrowMoveAssign)); |
| 2457 |
static_assert(!__is_nothrow_assignable(HasThrowMoveAssign, HasThrowMoveAssign)); |
| 2458 |
|
| 2459 |
static_assert(__is_assignable(HasNoThrowMoveAssign, HasNoThrowMoveAssign)); |
| 2460 |
static_assert(__is_assignable(HasThrowMoveAssign, HasThrowMoveAssign)); |
| 2461 |
} |
| 2462 |
|
| 2463 |
void has_trivial_move_assign() { |
| 2464 |
// n3376 12.8 [class.copy]/25 |
| 2465 |
// A copy/move assignment operator for class X is trivial if it |
| 2466 |
// is not user-provided, its declared parameter type is the same |
| 2467 |
// as if it had been implicitly declared, and if: |
| 2468 |
// - class X has no virtual functions (10.3) and no virtual base |
| 2469 |
// classes (10.1), and |
| 2470 |
// - the assignment operator selected to copy/move each direct |
| 2471 |
// base class subobject is trivial, and |
| 2472 |
// - for each non-static data member of X that is of class type |
| 2473 |
// (or array thereof), the assignment operator |
| 2474 |
// selected to copy/move that member is trivial; |
| 2475 |
static_assert(__has_trivial_move_assign(Int)); |
| 2476 |
static_assert(__has_trivial_move_assign(HasStaticMemberMoveAssign)); |
| 2477 |
static_assert(__has_trivial_move_assign(AllDeleted)); |
| 2478 |
static_assert(__has_trivial_move_assign(ACompleteType[])); |
| 2479 |
|
| 2480 |
static_assert(!__has_trivial_move_assign(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2481 |
static_assert(!__has_trivial_move_assign(HasVirt)); |
| 2482 |
static_assert(!__has_trivial_move_assign(DerivesVirt)); |
| 2483 |
static_assert(!__has_trivial_move_assign(HasMoveAssign)); |
| 2484 |
static_assert(!__has_trivial_move_assign(DerivesHasMoveAssign)); |
| 2485 |
static_assert(!__has_trivial_move_assign(HasMemberMoveAssign)); |
| 2486 |
static_assert(!__has_nothrow_move_assign(NoDefaultMoveAssignDueToUDCopyCtor)); |
| 2487 |
static_assert(!__has_nothrow_move_assign(NoDefaultMoveAssignDueToUDCopyAssign)); |
| 2488 |
} |
| 2489 |
|
| 2490 |
void has_nothrow_copy() { |
| 2491 |
static_assert(__has_nothrow_copy(Int)); |
| 2492 |
static_assert(__has_nothrow_copy(IntAr)); |
| 2493 |
static_assert(__has_nothrow_copy(Union)); |
| 2494 |
static_assert(__has_nothrow_copy(UnionAr)); |
| 2495 |
static_assert(__has_nothrow_copy(POD)); |
| 2496 |
static_assert(__has_nothrow_copy(const Int)); |
| 2497 |
static_assert(__has_nothrow_copy(ConstIntAr)); |
| 2498 |
static_assert(__has_nothrow_copy(ConstIntArAr)); |
| 2499 |
static_assert(__has_nothrow_copy(Derives)); |
| 2500 |
static_assert(__has_nothrow_copy(IntRef)); |
| 2501 |
static_assert(__has_nothrow_copy(HasDest)); |
| 2502 |
static_assert(__has_nothrow_copy(HasPriv)); |
| 2503 |
static_assert(__has_nothrow_copy(HasCons)); |
| 2504 |
static_assert(__has_nothrow_copy(HasRef)); |
| 2505 |
static_assert(__has_nothrow_copy(HasMove)); |
| 2506 |
static_assert(__has_nothrow_copy(HasCopyAssign)); |
| 2507 |
static_assert(__has_nothrow_copy(HasMoveAssign)); |
| 2508 |
static_assert(__has_nothrow_copy(HasNoThrowCopy)); |
| 2509 |
static_assert(__has_nothrow_copy(HasMultipleNoThrowCopy)); |
| 2510 |
static_assert(__has_nothrow_copy(HasVirtDest)); |
| 2511 |
static_assert(__has_nothrow_copy(HasTemplateCons)); |
| 2512 |
static_assert(__has_nothrow_copy(AllPrivate)); |
| 2513 |
static_assert(__has_nothrow_copy(DerivesAr)); |
| 2514 |
static_assert(__has_nothrow_copy(ACompleteType[])); |
| 2515 |
|
| 2516 |
static_assert(!__has_nothrow_copy(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2517 |
static_assert(!__has_nothrow_copy(HasCopy)); |
| 2518 |
static_assert(!__has_nothrow_copy(HasMultipleCopy)); |
| 2519 |
static_assert(!__has_nothrow_copy(VirtAr)); |
| 2520 |
static_assert(!__has_nothrow_copy(void)); |
| 2521 |
static_assert(!__has_nothrow_copy(cvoid)); |
| 2522 |
} |
| 2523 |
|
| 2524 |
void has_nothrow_constructor() { |
| 2525 |
static_assert(__has_nothrow_constructor(Int)); |
| 2526 |
static_assert(__has_nothrow_constructor(IntAr)); |
| 2527 |
static_assert(__has_nothrow_constructor(Union)); |
| 2528 |
static_assert(__has_nothrow_constructor(UnionAr)); |
| 2529 |
static_assert(__has_nothrow_constructor(POD)); |
| 2530 |
static_assert(__has_nothrow_constructor(Derives)); |
| 2531 |
static_assert(__has_nothrow_constructor(DerivesAr)); |
| 2532 |
static_assert(__has_nothrow_constructor(ConstIntAr)); |
| 2533 |
static_assert(__has_nothrow_constructor(ConstIntArAr)); |
| 2534 |
static_assert(__has_nothrow_constructor(HasDest)); |
| 2535 |
static_assert(__has_nothrow_constructor(HasPriv)); |
| 2536 |
static_assert(__has_nothrow_constructor(HasCopyAssign)); |
| 2537 |
static_assert(__has_nothrow_constructor(const Int)); |
| 2538 |
static_assert(__has_nothrow_constructor(HasNoThrowConstructor)); |
| 2539 |
static_assert(__has_nothrow_constructor(HasVirtDest)); |
| 2540 |
// static_assert(__has_nothrow_constructor(VirtAr)); // not implemented |
| 2541 |
static_assert(__has_nothrow_constructor(AllPrivate)); |
| 2542 |
static_assert(__has_nothrow_constructor(ACompleteType[])); |
| 2543 |
|
| 2544 |
static_assert(!__has_nothrow_constructor(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2545 |
static_assert(!__has_nothrow_constructor(HasCons)); |
| 2546 |
static_assert(!__has_nothrow_constructor(HasRef)); |
| 2547 |
static_assert(!__has_nothrow_constructor(HasCopy)); |
| 2548 |
static_assert(!__has_nothrow_constructor(HasMove)); |
| 2549 |
static_assert(!__has_nothrow_constructor(HasNoThrowConstructorWithArgs)); |
| 2550 |
static_assert(!__has_nothrow_constructor(IntRef)); |
| 2551 |
static_assert(!__has_nothrow_constructor(void)); |
| 2552 |
static_assert(!__has_nothrow_constructor(cvoid)); |
| 2553 |
static_assert(!__has_nothrow_constructor(HasTemplateCons)); |
| 2554 |
|
| 2555 |
static_assert(!__has_nothrow_constructor(HasMultipleDefaultConstructor1)); |
| 2556 |
static_assert(!__has_nothrow_constructor(HasMultipleDefaultConstructor2)); |
| 2557 |
} |
| 2558 |
|
| 2559 |
void has_virtual_destructor() { |
| 2560 |
static_assert(!__has_virtual_destructor(Int)); |
| 2561 |
static_assert(!__has_virtual_destructor(IntAr)); |
| 2562 |
static_assert(!__has_virtual_destructor(Union)); |
| 2563 |
static_assert(!__has_virtual_destructor(UnionAr)); |
| 2564 |
static_assert(!__has_virtual_destructor(POD)); |
| 2565 |
static_assert(!__has_virtual_destructor(Derives)); |
| 2566 |
static_assert(!__has_virtual_destructor(DerivesAr)); |
| 2567 |
static_assert(!__has_virtual_destructor(const Int)); |
| 2568 |
static_assert(!__has_virtual_destructor(ConstIntAr)); |
| 2569 |
static_assert(!__has_virtual_destructor(ConstIntArAr)); |
| 2570 |
static_assert(!__has_virtual_destructor(HasDest)); |
| 2571 |
static_assert(!__has_virtual_destructor(HasPriv)); |
| 2572 |
static_assert(!__has_virtual_destructor(HasCons)); |
| 2573 |
static_assert(!__has_virtual_destructor(HasRef)); |
| 2574 |
static_assert(!__has_virtual_destructor(HasCopy)); |
| 2575 |
static_assert(!__has_virtual_destructor(HasMove)); |
| 2576 |
static_assert(!__has_virtual_destructor(HasCopyAssign)); |
| 2577 |
static_assert(!__has_virtual_destructor(HasMoveAssign)); |
| 2578 |
static_assert(!__has_virtual_destructor(IntRef)); |
| 2579 |
static_assert(!__has_virtual_destructor(VirtAr)); |
| 2580 |
static_assert(!__has_virtual_destructor(ACompleteType[])); |
| 2581 |
|
| 2582 |
static_assert(!__has_virtual_destructor(AnIncompleteType[])); // expected-error {{incomplete type}} |
| 2583 |
static_assert(__has_virtual_destructor(HasVirtDest)); |
| 2584 |
static_assert(__has_virtual_destructor(DerivedVirtDest)); |
| 2585 |
static_assert(!__has_virtual_destructor(VirtDestAr)); |
| 2586 |
static_assert(!__has_virtual_destructor(void)); |
| 2587 |
static_assert(!__has_virtual_destructor(cvoid)); |
| 2588 |
static_assert(!__has_virtual_destructor(AllPrivate)); |
| 2589 |
} |
| 2590 |
|
| 2591 |
|
| 2592 |
class Base {}; |
| 2593 |
class Derived : Base {}; |
| 2594 |
class Derived2a : Derived {}; |
| 2595 |
class Derived2b : Derived {}; |
| 2596 |
class Derived3 : virtual Derived2a, virtual Derived2b {}; |
| 2597 |
template<typename T> struct BaseA { T a; }; |
| 2598 |
template<typename T> struct DerivedB : BaseA<T> { }; |
| 2599 |
template<typename T> struct CrazyDerived : T { }; |
| 2600 |
|
| 2601 |
|
| 2602 |
class class_forward; // expected-note 4 {{forward declaration of 'class_forward'}} |
| 2603 |
|
| 2604 |
template <class T> class DerivedTemp : Base {}; |
| 2605 |
template <class T> class NonderivedTemp {}; |
| 2606 |
template <class T> class UndefinedTemp; // expected-note 2 {{declared here}} |
| 2607 |
|
| 2608 |
void is_base_of() { |
| 2609 |
static_assert(__is_base_of(Base, Derived)); |
| 2610 |
static_assert(__is_base_of(const Base, Derived)); |
| 2611 |
static_assert(!__is_base_of(Derived, Base)); |
| 2612 |
static_assert(!__is_base_of(Derived, int)); |
| 2613 |
static_assert(__is_base_of(Base, Base)); |
| 2614 |
static_assert(__is_base_of(Base, Derived3)); |
| 2615 |
static_assert(__is_base_of(Derived, Derived3)); |
| 2616 |
static_assert(__is_base_of(Derived2b, Derived3)); |
| 2617 |
static_assert(__is_base_of(Derived2a, Derived3)); |
| 2618 |
static_assert(__is_base_of(BaseA<int>, DerivedB<int>)); |
| 2619 |
static_assert(!__is_base_of(DerivedB<int>, BaseA<int>)); |
| 2620 |
static_assert(__is_base_of(Base, CrazyDerived<Base>)); |
| 2621 |
static_assert(!__is_base_of(Union, Union)); |
| 2622 |
static_assert(__is_base_of(Empty, Empty)); |
| 2623 |
static_assert(__is_base_of(class_forward, class_forward)); |
| 2624 |
static_assert(!__is_base_of(Empty, class_forward)); // expected-error {{incomplete type 'class_forward' used in type trait expression}} |
| 2625 |
static_assert(!__is_base_of(Base&, Derived&)); |
| 2626 |
static_assert(!__is_base_of(Base[10], Derived[10])); |
| 2627 |
static_assert(!__is_base_of(int, int)); |
| 2628 |
static_assert(!__is_base_of(long, int)); |
| 2629 |
static_assert(__is_base_of(Base, DerivedTemp<int>)); |
| 2630 |
static_assert(!__is_base_of(Base, NonderivedTemp<int>)); |
| 2631 |
static_assert(!__is_base_of(Base, UndefinedTemp<int>)); // expected-error {{implicit instantiation of undefined template 'UndefinedTemp<int>'}} |
| 2632 |
|
| 2633 |
static_assert(!__is_base_of(IncompleteUnion, IncompleteUnion)); |
| 2634 |
static_assert(!__is_base_of(Union, IncompleteUnion)); |
| 2635 |
static_assert(!__is_base_of(IncompleteUnion, Union)); |
| 2636 |
static_assert(!__is_base_of(IncompleteStruct, IncompleteUnion)); |
| 2637 |
static_assert(!__is_base_of(IncompleteUnion, IncompleteStruct)); |
| 2638 |
static_assert(!__is_base_of(Empty, IncompleteUnion)); |
| 2639 |
static_assert(!__is_base_of(IncompleteUnion, Empty)); |
| 2640 |
static_assert(!__is_base_of(int, IncompleteUnion)); |
| 2641 |
static_assert(!__is_base_of(IncompleteUnion, int)); |
| 2642 |
static_assert(!__is_base_of(Empty, Union)); |
| 2643 |
static_assert(!__is_base_of(Union, Empty)); |
| 2644 |
static_assert(!__is_base_of(int, Empty)); |
| 2645 |
static_assert(!__is_base_of(Union, int)); |
| 2646 |
|
| 2647 |
static_assert(__is_base_of(Base, Derived)); |
| 2648 |
static_assert(!__is_base_of(Derived, Base)); |
| 2649 |
|
| 2650 |
static_assert(__is_base_of(Base, CrazyDerived<Base>)); |
| 2651 |
static_assert(!__is_base_of(CrazyDerived<Base>, Base)); |
| 2652 |
|
| 2653 |
static_assert(__is_base_of(BaseA<int>, DerivedB<int>)); |
| 2654 |
static_assert(!__is_base_of(DerivedB<int>, BaseA<int>)); |
| 2655 |
} |
| 2656 |
|
| 2657 |
struct DerivedTransitiveViaNonVirtual : Derived3 {}; |
| 2658 |
struct DerivedTransitiveViaVirtual : virtual Derived3 {}; |
| 2659 |
|
| 2660 |
template <typename T> |
| 2661 |
struct CrazyDerivedVirtual : virtual T {}; |
| 2662 |
|
| 2663 |
struct DerivedPrivate : private virtual Base {}; |
| 2664 |
struct DerivedProtected : protected virtual Base {}; |
| 2665 |
struct DerivedPrivatePrivate : private DerivedPrivate {}; |
| 2666 |
struct DerivedPrivateProtected : private DerivedProtected {}; |
| 2667 |
struct DerivedProtectedPrivate : protected DerivedProtected {}; |
| 2668 |
struct DerivedProtectedProtected : protected DerivedProtected {}; |
| 2669 |
|
| 2670 |
void is_virtual_base_of(int n) { |
| 2671 |
static_assert(!__builtin_is_virtual_base_of(Base, Derived)); |
| 2672 |
static_assert(!__builtin_is_virtual_base_of(const Base, Derived)); |
| 2673 |
static_assert(!__builtin_is_virtual_base_of(Derived, Base)); |
| 2674 |
static_assert(!__builtin_is_virtual_base_of(Derived, int)); |
| 2675 |
static_assert(!__builtin_is_virtual_base_of(Base, Base)); |
| 2676 |
static_assert(!__builtin_is_virtual_base_of(Base, Derived3)); |
| 2677 |
static_assert(!__builtin_is_virtual_base_of(Derived, Derived3)); |
| 2678 |
static_assert(__builtin_is_virtual_base_of(Derived2b, Derived3)); |
| 2679 |
static_assert(__builtin_is_virtual_base_of(Derived2a, Derived3)); |
| 2680 |
static_assert(!__builtin_is_virtual_base_of(BaseA<int>, DerivedB<int>)); |
| 2681 |
static_assert(!__builtin_is_virtual_base_of(DerivedB<int>, BaseA<int>)); |
| 2682 |
static_assert(!__builtin_is_virtual_base_of(Union, Union)); |
| 2683 |
static_assert(!__builtin_is_virtual_base_of(Empty, Empty)); |
| 2684 |
static_assert(!__builtin_is_virtual_base_of(class_forward, class_forward)); // expected-error {{incomplete type 'class_forward' where a complete type is required}} |
| 2685 |
static_assert(!__builtin_is_virtual_base_of(Empty, class_forward)); // expected-error {{incomplete type 'class_forward' where a complete type is required}} |
| 2686 |
static_assert(!__builtin_is_virtual_base_of(class_forward, Empty)); |
| 2687 |
static_assert(!__builtin_is_virtual_base_of(Base&, Derived&)); |
| 2688 |
static_assert(!__builtin_is_virtual_base_of(Base[10], Derived[10])); |
| 2689 |
static_assert(!__builtin_is_virtual_base_of(Base[n], Derived[n])); // expected-error 2 {{variable length arrays are not supported in '__builtin_is_virtual_base_of'}} |
| 2690 |
static_assert(!__builtin_is_virtual_base_of(int, int)); |
| 2691 |
static_assert(!__builtin_is_virtual_base_of(int[], int[])); |
| 2692 |
static_assert(!__builtin_is_virtual_base_of(long, int)); |
| 2693 |
static_assert(!__builtin_is_virtual_base_of(Base, DerivedTemp<int>)); |
| 2694 |
static_assert(!__builtin_is_virtual_base_of(Base, NonderivedTemp<int>)); |
| 2695 |
static_assert(!__builtin_is_virtual_base_of(Base, UndefinedTemp<int>)); // expected-error {{implicit instantiation of undefined template 'UndefinedTemp<int>'}} |
| 2696 |
static_assert(__builtin_is_virtual_base_of(Base, DerivedPrivate)); |
| 2697 |
static_assert(__builtin_is_virtual_base_of(Base, DerivedProtected)); |
| 2698 |
static_assert(__builtin_is_virtual_base_of(Base, DerivedPrivatePrivate)); |
| 2699 |
static_assert(__builtin_is_virtual_base_of(Base, DerivedPrivateProtected)); |
| 2700 |
static_assert(__builtin_is_virtual_base_of(Base, DerivedProtectedPrivate)); |
| 2701 |
static_assert(__builtin_is_virtual_base_of(Base, DerivedProtectedProtected)); |
| 2702 |
static_assert(__builtin_is_virtual_base_of(Derived2a, DerivedTransitiveViaNonVirtual)); |
| 2703 |
static_assert(__builtin_is_virtual_base_of(Derived2b, DerivedTransitiveViaNonVirtual)); |
| 2704 |
static_assert(__builtin_is_virtual_base_of(Derived2a, DerivedTransitiveViaVirtual)); |
| 2705 |
static_assert(__builtin_is_virtual_base_of(Derived2b, DerivedTransitiveViaVirtual)); |
| 2706 |
static_assert(!__builtin_is_virtual_base_of(Base, CrazyDerived<Base>)); |
| 2707 |
static_assert(!__builtin_is_virtual_base_of(CrazyDerived<Base>, Base)); |
| 2708 |
static_assert(__builtin_is_virtual_base_of(Base, CrazyDerivedVirtual<Base>)); |
| 2709 |
static_assert(!__builtin_is_virtual_base_of(CrazyDerivedVirtual<Base>, Base)); |
| 2710 |
|
| 2711 |
static_assert(!__builtin_is_virtual_base_of(IncompleteUnion, IncompleteUnion)); |
| 2712 |
static_assert(!__builtin_is_virtual_base_of(Union, IncompleteUnion)); |
| 2713 |
static_assert(!__builtin_is_virtual_base_of(IncompleteUnion, Union)); |
| 2714 |
static_assert(!__builtin_is_virtual_base_of(IncompleteStruct, IncompleteUnion)); |
| 2715 |
static_assert(!__builtin_is_virtual_base_of(IncompleteUnion, IncompleteStruct)); |
| 2716 |
static_assert(!__builtin_is_virtual_base_of(Empty, IncompleteUnion)); |
| 2717 |
static_assert(!__builtin_is_virtual_base_of(IncompleteUnion, Empty)); |
| 2718 |
static_assert(!__builtin_is_virtual_base_of(int, IncompleteUnion)); |
| 2719 |
static_assert(!__builtin_is_virtual_base_of(IncompleteUnion, int)); |
| 2720 |
static_assert(!__builtin_is_virtual_base_of(Empty, Union)); |
| 2721 |
static_assert(!__builtin_is_virtual_base_of(Union, Empty)); |
| 2722 |
static_assert(!__builtin_is_virtual_base_of(int, Empty)); |
| 2723 |
static_assert(!__builtin_is_virtual_base_of(Union, int)); |
| 2724 |
static_assert(!__builtin_is_virtual_base_of(IncompleteStruct, IncompleteStruct[n])); // expected-error {{variable length arrays are not supported in '__builtin_is_virtual_base_of'}} |
| 2725 |
} |
| 2726 |
|
| 2727 |
template<class T, class U> |
| 2728 |
class TemplateClass {}; |
| 2729 |
|
| 2730 |
template<class T> |
| 2731 |
using TemplateAlias = TemplateClass<T, int>; |
| 2732 |
|
| 2733 |
typedef class Base BaseTypedef; |
| 2734 |
|
| 2735 |
void is_same() |
| 2736 |
{ |
| 2737 |
static_assert(__is_same(Base, Base)); |
| 2738 |
static_assert(__is_same(Base, BaseTypedef)); |
| 2739 |
static_assert(__is_same(TemplateClass<int, int>, TemplateAlias<int>)); |
| 2740 |
|
| 2741 |
static_assert(!__is_same(Base, const Base)); |
| 2742 |
static_assert(!__is_same(Base, Base&)); |
| 2743 |
static_assert(!__is_same(Base, Derived)); |
| 2744 |
|
| 2745 |
// __is_same_as is a GCC compatibility synonym for __is_same. |
| 2746 |
static_assert(__is_same_as(int, int)); |
| 2747 |
static_assert(!__is_same_as(int, float)); |
| 2748 |
} |
| 2749 |
|
| 2750 |
struct IntWrapper |
| 2751 |
{ |
| 2752 |
int value; |
| 2753 |
IntWrapper(int _value) : value(_value) {} |
| 2754 |
operator int() const noexcept { |
| 2755 |
return value; |
| 2756 |
} |
| 2757 |
}; |
| 2758 |
|
| 2759 |
struct FloatWrapper |
| 2760 |
{ |
| 2761 |
float value; |
| 2762 |
FloatWrapper(float _value) noexcept : value(_value) {} |
| 2763 |
FloatWrapper(const IntWrapper& obj) |
| 2764 |
: value(static_cast<float>(obj.value)) {} |
| 2765 |
operator float() const { |
| 2766 |
return value; |
| 2767 |
} |
| 2768 |
operator IntWrapper() const { |
| 2769 |
return IntWrapper(static_cast<int>(value)); |
| 2770 |
} |
| 2771 |
}; |
| 2772 |
|
| 2773 |
template<typename A, typename B, bool result = __is_convertible(A, B)> |
| 2774 |
static constexpr bool is_convertible_sfinae() { return result; } |
| 2775 |
|
| 2776 |
void is_convertible() |
| 2777 |
{ |
| 2778 |
static_assert(__is_convertible(IntWrapper, IntWrapper)); |
| 2779 |
static_assert(__is_convertible(IntWrapper, const IntWrapper)); |
| 2780 |
static_assert(__is_convertible(IntWrapper, int)); |
| 2781 |
static_assert(__is_convertible(int, IntWrapper)); |
| 2782 |
static_assert(__is_convertible(IntWrapper, FloatWrapper)); |
| 2783 |
static_assert(__is_convertible(FloatWrapper, IntWrapper)); |
| 2784 |
static_assert(__is_convertible(FloatWrapper, float)); |
| 2785 |
static_assert(__is_convertible(float, FloatWrapper)); |
| 2786 |
static_assert(__is_convertible(IntWrapper, IntWrapper&&)); |
| 2787 |
static_assert(__is_convertible(IntWrapper, const IntWrapper&)); |
| 2788 |
static_assert(__is_convertible(IntWrapper, int&&)); |
| 2789 |
static_assert(__is_convertible(IntWrapper, const int&)); |
| 2790 |
static_assert(__is_convertible(int, IntWrapper&&)); |
| 2791 |
static_assert(__is_convertible(int, const IntWrapper&)); |
| 2792 |
static_assert(__is_convertible(IntWrapper, FloatWrapper&&)); |
| 2793 |
static_assert(__is_convertible(IntWrapper, const FloatWrapper&)); |
| 2794 |
static_assert(__is_convertible(FloatWrapper, IntWrapper&&)); |
| 2795 |
static_assert(__is_convertible(FloatWrapper, const IntWrapper&&)); |
| 2796 |
static_assert(__is_convertible(FloatWrapper, float&&)); |
| 2797 |
static_assert(__is_convertible(FloatWrapper, const float&)); |
| 2798 |
static_assert(__is_convertible(float, FloatWrapper&&)); |
| 2799 |
static_assert(__is_convertible(float, const FloatWrapper&)); |
| 2800 |
|
| 2801 |
static_assert(!__is_convertible(AllPrivate, AllPrivate)); |
| 2802 |
// Make sure we don't emit "calling a private constructor" in SFINAE context. |
| 2803 |
static_assert(!is_convertible_sfinae<AllPrivate, AllPrivate>()); |
| 2804 |
} |
| 2805 |
|
| 2806 |
void is_nothrow_convertible() |
| 2807 |
{ |
| 2808 |
static_assert(__is_nothrow_convertible(IntWrapper, IntWrapper)); |
| 2809 |
static_assert(__is_nothrow_convertible(IntWrapper, const IntWrapper)); |
| 2810 |
static_assert(__is_nothrow_convertible(IntWrapper, int)); |
| 2811 |
static_assert(!__is_nothrow_convertible(int, IntWrapper)); |
| 2812 |
static_assert(!__is_nothrow_convertible(IntWrapper, FloatWrapper)); |
| 2813 |
static_assert(!__is_nothrow_convertible(FloatWrapper, IntWrapper)); |
| 2814 |
static_assert(!__is_nothrow_convertible(FloatWrapper, float)); |
| 2815 |
static_assert(__is_nothrow_convertible(float, FloatWrapper)); |
| 2816 |
static_assert(__is_nothrow_convertible(IntWrapper, IntWrapper&&)); |
| 2817 |
static_assert(__is_nothrow_convertible(IntWrapper, const IntWrapper&)); |
| 2818 |
static_assert(__is_nothrow_convertible(IntWrapper, int&&)); |
| 2819 |
static_assert(__is_nothrow_convertible(IntWrapper, const int&)); |
| 2820 |
static_assert(!__is_nothrow_convertible(int, IntWrapper&&)); |
| 2821 |
static_assert(!__is_nothrow_convertible(int, const IntWrapper&)); |
| 2822 |
static_assert(!__is_nothrow_convertible(IntWrapper, FloatWrapper&&)); |
| 2823 |
static_assert(!__is_nothrow_convertible(IntWrapper, const FloatWrapper&)); |
| 2824 |
static_assert(!__is_nothrow_convertible(FloatWrapper, IntWrapper&&)); |
| 2825 |
static_assert(!__is_nothrow_convertible(FloatWrapper, const IntWrapper&)); |
| 2826 |
static_assert(!__is_nothrow_convertible(FloatWrapper, float&&)); |
| 2827 |
static_assert(!__is_nothrow_convertible(FloatWrapper, const float&)); |
| 2828 |
static_assert(__is_nothrow_convertible(float, FloatWrapper&&)); |
| 2829 |
static_assert(__is_nothrow_convertible(float, const FloatWrapper&)); |
| 2830 |
} |
| 2831 |
|
| 2832 |
struct FromInt { FromInt(int); }; |
| 2833 |
struct ToInt { operator int(); }; |
| 2834 |
typedef void Function(); |
| 2835 |
|
| 2836 |
void is_convertible_to(); |
| 2837 |
class PrivateCopy { |
| 2838 |
PrivateCopy(const PrivateCopy&); |
| 2839 |
friend void is_convertible_to(); |
| 2840 |
}; |
| 2841 |
|
| 2842 |
template<typename T> |
| 2843 |
struct X0 { |
| 2844 |
template<typename U> X0(const X0<U>&); |
| 2845 |
}; |
| 2846 |
|
| 2847 |
struct Abstract { virtual void f() = 0; }; |
| 2848 |
|
| 2849 |
void is_convertible_to() { |
| 2850 |
static_assert(__is_convertible_to(Int, Int)); |
| 2851 |
static_assert(!__is_convertible_to(Int, IntAr)); |
| 2852 |
static_assert(!__is_convertible_to(IntAr, IntAr)); |
| 2853 |
static_assert(__is_convertible_to(void, void)); |
| 2854 |
static_assert(__is_convertible_to(cvoid, void)); |
| 2855 |
static_assert(__is_convertible_to(void, cvoid)); |
| 2856 |
static_assert(__is_convertible_to(cvoid, cvoid)); |
| 2857 |
static_assert(__is_convertible_to(int, FromInt)); |
| 2858 |
static_assert(__is_convertible_to(long, FromInt)); |
| 2859 |
static_assert(__is_convertible_to(double, FromInt)); |
| 2860 |
static_assert(__is_convertible_to(const int, FromInt)); |
| 2861 |
static_assert(__is_convertible_to(const int&, FromInt)); |
| 2862 |
static_assert(__is_convertible_to(ToInt, int)); |
| 2863 |
static_assert(__is_convertible_to(ToInt, const int&)); |
| 2864 |
static_assert(__is_convertible_to(ToInt, long)); |
| 2865 |
static_assert(!__is_convertible_to(ToInt, int&)); |
| 2866 |
static_assert(!__is_convertible_to(ToInt, FromInt)); |
| 2867 |
static_assert(__is_convertible_to(IntAr&, IntAr&)); |
| 2868 |
static_assert(__is_convertible_to(IntAr&, const IntAr&)); |
| 2869 |
static_assert(!__is_convertible_to(const IntAr&, IntAr&)); |
| 2870 |
static_assert(!__is_convertible_to(Function, Function)); |
| 2871 |
static_assert(!__is_convertible_to(PrivateCopy, PrivateCopy)); |
| 2872 |
static_assert(__is_convertible_to(X0<int>, X0<float>)); |
| 2873 |
static_assert(!__is_convertible_to(Abstract, Abstract)); |
| 2874 |
} |
| 2875 |
|
| 2876 |
namespace is_convertible_to_instantiate { |
| 2877 |
// Make sure we don't try to instantiate the constructor. |
| 2878 |
template<int x> class A { A(int) { int a[x]; } }; |
| 2879 |
int x = __is_convertible_to(int, A<-1>); |
| 2880 |
} |
| 2881 |
|
| 2882 |
void is_trivial() |
| 2883 |
{ |
| 2884 |
static_assert(__is_trivial(int)); |
| 2885 |
static_assert(__is_trivial(Enum)); |
| 2886 |
static_assert(__is_trivial(POD)); |
| 2887 |
static_assert(__is_trivial(Int)); |
| 2888 |
static_assert(__is_trivial(IntAr)); |
| 2889 |
static_assert(__is_trivial(IntArNB)); |
| 2890 |
static_assert(__is_trivial(Statics)); |
| 2891 |
static_assert(__is_trivial(Empty)); |
| 2892 |
static_assert(__is_trivial(EmptyUnion)); |
| 2893 |
static_assert(__is_trivial(Union)); |
| 2894 |
static_assert(__is_trivial(Derives)); |
| 2895 |
static_assert(__is_trivial(DerivesAr)); |
| 2896 |
static_assert(__is_trivial(DerivesArNB)); |
| 2897 |
static_assert(__is_trivial(DerivesEmpty)); |
| 2898 |
static_assert(__is_trivial(HasFunc)); |
| 2899 |
static_assert(__is_trivial(HasOp)); |
| 2900 |
static_assert(__is_trivial(HasConv)); |
| 2901 |
static_assert(__is_trivial(HasAssign)); |
| 2902 |
static_assert(__is_trivial(HasAnonymousUnion)); |
| 2903 |
static_assert(__is_trivial(HasPriv)); |
| 2904 |
static_assert(__is_trivial(HasProt)); |
| 2905 |
static_assert(__is_trivial(DerivesHasPriv)); |
| 2906 |
static_assert(__is_trivial(DerivesHasProt)); |
| 2907 |
static_assert(__is_trivial(Vector)); |
| 2908 |
static_assert(__is_trivial(VectorExt)); |
| 2909 |
|
| 2910 |
static_assert(!__is_trivial(HasCons)); |
| 2911 |
static_assert(!__is_trivial(HasCopyAssign)); |
| 2912 |
static_assert(!__is_trivial(HasMoveAssign)); |
| 2913 |
static_assert(!__is_trivial(HasDest)); |
| 2914 |
static_assert(!__is_trivial(HasRef)); |
| 2915 |
static_assert(!__is_trivial(HasNonPOD)); |
| 2916 |
static_assert(!__is_trivial(HasVirt)); |
| 2917 |
static_assert(!__is_trivial(DerivesHasCons)); |
| 2918 |
static_assert(!__is_trivial(DerivesHasCopyAssign)); |
| 2919 |
static_assert(!__is_trivial(DerivesHasMoveAssign)); |
| 2920 |
static_assert(!__is_trivial(DerivesHasDest)); |
| 2921 |
static_assert(!__is_trivial(DerivesHasRef)); |
| 2922 |
static_assert(!__is_trivial(DerivesHasVirt)); |
| 2923 |
static_assert(!__is_trivial(void)); |
| 2924 |
static_assert(!__is_trivial(cvoid)); |
| 2925 |
} |
| 2926 |
|
| 2927 |
template<typename T> struct TriviallyConstructibleTemplate {}; |
| 2928 |
|
| 2929 |
template<typename A, typename B, bool result = __is_assignable(A, B)> |
| 2930 |
static constexpr bool is_assignable_sfinae() { return result; } |
| 2931 |
|
| 2932 |
void trivial_checks() |
| 2933 |
{ |
| 2934 |
static_assert(__is_trivially_copyable(int)); |
| 2935 |
static_assert(__is_trivially_copyable(Enum)); |
| 2936 |
static_assert(__is_trivially_copyable(POD)); |
| 2937 |
static_assert(__is_trivially_copyable(Int)); |
| 2938 |
static_assert(__is_trivially_copyable(IntAr)); |
| 2939 |
static_assert(__is_trivially_copyable(IntArNB)); |
| 2940 |
static_assert(__is_trivially_copyable(Statics)); |
| 2941 |
static_assert(__is_trivially_copyable(Empty)); |
| 2942 |
static_assert(__is_trivially_copyable(EmptyUnion)); |
| 2943 |
static_assert(__is_trivially_copyable(Union)); |
| 2944 |
static_assert(__is_trivially_copyable(Derives)); |
| 2945 |
static_assert(__is_trivially_copyable(DerivesAr)); |
| 2946 |
static_assert(__is_trivially_copyable(DerivesArNB)); |
| 2947 |
static_assert(__is_trivially_copyable(DerivesEmpty)); |
| 2948 |
static_assert(__is_trivially_copyable(HasFunc)); |
| 2949 |
static_assert(__is_trivially_copyable(HasOp)); |
| 2950 |
static_assert(__is_trivially_copyable(HasConv)); |
| 2951 |
static_assert(__is_trivially_copyable(HasAssign)); |
| 2952 |
static_assert(__is_trivially_copyable(HasAnonymousUnion)); |
| 2953 |
static_assert(__is_trivially_copyable(HasPriv)); |
| 2954 |
static_assert(__is_trivially_copyable(HasProt)); |
| 2955 |
static_assert(__is_trivially_copyable(DerivesHasPriv)); |
| 2956 |
static_assert(__is_trivially_copyable(DerivesHasProt)); |
| 2957 |
static_assert(__is_trivially_copyable(Vector)); |
| 2958 |
static_assert(__is_trivially_copyable(VectorExt)); |
| 2959 |
static_assert(__is_trivially_copyable(HasCons)); |
| 2960 |
static_assert(__is_trivially_copyable(HasRef)); |
| 2961 |
static_assert(__is_trivially_copyable(HasNonPOD)); |
| 2962 |
static_assert(__is_trivially_copyable(DerivesHasCons)); |
| 2963 |
static_assert(__is_trivially_copyable(DerivesHasRef)); |
| 2964 |
static_assert(__is_trivially_copyable(NonTrivialDefault)); |
| 2965 |
static_assert(__is_trivially_copyable(NonTrivialDefault[])); |
| 2966 |
static_assert(__is_trivially_copyable(NonTrivialDefault[3])); |
| 2967 |
|
| 2968 |
static_assert(!__is_trivially_copyable(HasCopyAssign)); |
| 2969 |
static_assert(!__is_trivially_copyable(HasMoveAssign)); |
| 2970 |
static_assert(!__is_trivially_copyable(HasDest)); |
| 2971 |
static_assert(!__is_trivially_copyable(HasVirt)); |
| 2972 |
static_assert(!__is_trivially_copyable(DerivesHasCopyAssign)); |
| 2973 |
static_assert(!__is_trivially_copyable(DerivesHasMoveAssign)); |
| 2974 |
static_assert(!__is_trivially_copyable(DerivesHasDest)); |
| 2975 |
static_assert(!__is_trivially_copyable(DerivesHasVirt)); |
| 2976 |
static_assert(!__is_trivially_copyable(void)); |
| 2977 |
static_assert(!__is_trivially_copyable(cvoid)); |
| 2978 |
|
| 2979 |
static_assert((__is_trivially_constructible(int))); |
| 2980 |
static_assert((__is_trivially_constructible(int, int))); |
| 2981 |
static_assert((__is_trivially_constructible(int, float))); |
| 2982 |
static_assert((__is_trivially_constructible(int, int&))); |
| 2983 |
static_assert((__is_trivially_constructible(int, const int&))); |
| 2984 |
static_assert((__is_trivially_constructible(int, int))); |
| 2985 |
static_assert((__is_trivially_constructible(HasCopyAssign, HasCopyAssign))); |
| 2986 |
static_assert((__is_trivially_constructible(HasCopyAssign, const HasCopyAssign&))); |
| 2987 |
static_assert((__is_trivially_constructible(HasCopyAssign, HasCopyAssign&&))); |
| 2988 |
static_assert((__is_trivially_constructible(HasCopyAssign))); |
| 2989 |
static_assert((__is_trivially_constructible(NonTrivialDefault, |
| 2990 |
const NonTrivialDefault&))); |
| 2991 |
static_assert((__is_trivially_constructible(NonTrivialDefault, |
| 2992 |
NonTrivialDefault&&))); |
| 2993 |
static_assert((__is_trivially_constructible(AllDefaulted))); |
| 2994 |
static_assert((__is_trivially_constructible(AllDefaulted, |
| 2995 |
const AllDefaulted &))); |
| 2996 |
static_assert((__is_trivially_constructible(AllDefaulted, |
| 2997 |
AllDefaulted &&))); |
| 2998 |
|
| 2999 |
static_assert(!(__is_trivially_constructible(int, int*))); |
| 3000 |
static_assert(!(__is_trivially_constructible(NonTrivialDefault))); |
| 3001 |
static_assert(!(__is_trivially_constructible(ThreeArgCtor, int*, char*, int&))); |
| 3002 |
static_assert(!(__is_trivially_constructible(AllDeleted))); |
| 3003 |
static_assert(!(__is_trivially_constructible(AllDeleted, |
| 3004 |
const AllDeleted &))); |
| 3005 |
static_assert(!(__is_trivially_constructible(AllDeleted, |
| 3006 |
AllDeleted &&))); |
| 3007 |
static_assert(!(__is_trivially_constructible(ExtDefaulted))); |
| 3008 |
static_assert(!(__is_trivially_constructible(ExtDefaulted, |
| 3009 |
const ExtDefaulted &))); |
| 3010 |
static_assert(!(__is_trivially_constructible(ExtDefaulted, |
| 3011 |
ExtDefaulted &&))); |
| 3012 |
|
| 3013 |
static_assert((__is_trivially_constructible(TriviallyConstructibleTemplate<int>))); |
| 3014 |
static_assert(!(__is_trivially_constructible(class_forward))); // expected-error {{incomplete type 'class_forward' used in type trait expression}} |
| 3015 |
static_assert(!(__is_trivially_constructible(class_forward[]))); |
| 3016 |
static_assert(!(__is_trivially_constructible(void))); |
| 3017 |
|
| 3018 |
static_assert((__is_trivially_assignable(int&, int))); |
| 3019 |
static_assert((__is_trivially_assignable(int&, int&))); |
| 3020 |
static_assert((__is_trivially_assignable(int&, int&&))); |
| 3021 |
static_assert((__is_trivially_assignable(int&, const int&))); |
| 3022 |
static_assert((__is_trivially_assignable(POD&, POD))); |
| 3023 |
static_assert((__is_trivially_assignable(POD&, POD&))); |
| 3024 |
static_assert((__is_trivially_assignable(POD&, POD&&))); |
| 3025 |
static_assert((__is_trivially_assignable(POD&, const POD&))); |
| 3026 |
static_assert((__is_trivially_assignable(int*&, int*))); |
| 3027 |
static_assert((__is_trivially_assignable(AllDefaulted, |
| 3028 |
const AllDefaulted &))); |
| 3029 |
static_assert((__is_trivially_assignable(AllDefaulted, |
| 3030 |
AllDefaulted &&))); |
| 3031 |
|
| 3032 |
static_assert(!(__is_trivially_assignable(int*&, float*))); |
| 3033 |
static_assert(!(__is_trivially_assignable(HasCopyAssign&, HasCopyAssign))); |
| 3034 |
static_assert(!(__is_trivially_assignable(HasCopyAssign&, HasCopyAssign&))); |
| 3035 |
static_assert(!(__is_trivially_assignable(HasCopyAssign&, const HasCopyAssign&))); |
| 3036 |
static_assert(!(__is_trivially_assignable(HasCopyAssign&, HasCopyAssign&&))); |
| 3037 |
static_assert(!(__is_trivially_assignable(TrivialMoveButNotCopy&, |
| 3038 |
TrivialMoveButNotCopy&))); |
| 3039 |
static_assert(!(__is_trivially_assignable(TrivialMoveButNotCopy&, |
| 3040 |
const TrivialMoveButNotCopy&))); |
| 3041 |
static_assert(!(__is_trivially_assignable(AllDeleted, |
| 3042 |
const AllDeleted &))); |
| 3043 |
static_assert(!(__is_trivially_assignable(AllDeleted, |
| 3044 |
AllDeleted &&))); |
| 3045 |
static_assert(!(__is_trivially_assignable(ExtDefaulted, |
| 3046 |
const ExtDefaulted &))); |
| 3047 |
static_assert(!(__is_trivially_assignable(ExtDefaulted, |
| 3048 |
ExtDefaulted &&))); |
| 3049 |
|
| 3050 |
static_assert((__is_trivially_assignable(HasDefaultTrivialCopyAssign&, |
| 3051 |
HasDefaultTrivialCopyAssign&))); |
| 3052 |
static_assert((__is_trivially_assignable(HasDefaultTrivialCopyAssign&, |
| 3053 |
const HasDefaultTrivialCopyAssign&))); |
| 3054 |
static_assert((__is_trivially_assignable(TrivialMoveButNotCopy&, |
| 3055 |
TrivialMoveButNotCopy))); |
| 3056 |
static_assert((__is_trivially_assignable(TrivialMoveButNotCopy&, |
| 3057 |
TrivialMoveButNotCopy&&))); |
| 3058 |
static_assert((__is_trivially_assignable(int&, int))); |
| 3059 |
static_assert((__is_trivially_assignable(int&, int&))); |
| 3060 |
static_assert((__is_trivially_assignable(int&, int&&))); |
| 3061 |
static_assert((__is_trivially_assignable(int&, const int&))); |
| 3062 |
static_assert((__is_trivially_assignable(POD&, POD))); |
| 3063 |
static_assert((__is_trivially_assignable(POD&, POD&))); |
| 3064 |
static_assert((__is_trivially_assignable(POD&, POD&&))); |
| 3065 |
static_assert((__is_trivially_assignable(POD&, const POD&))); |
| 3066 |
static_assert((__is_trivially_assignable(int*&, int*))); |
| 3067 |
static_assert((__is_trivially_assignable(AllDefaulted, |
| 3068 |
const AllDefaulted &))); |
| 3069 |
static_assert((__is_trivially_assignable(AllDefaulted, |
| 3070 |
AllDefaulted &&))); |
| 3071 |
|
| 3072 |
static_assert(!(__is_assignable(int *&, float *))); |
| 3073 |
static_assert((__is_assignable(HasCopyAssign &, HasCopyAssign))); |
| 3074 |
static_assert((__is_assignable(HasCopyAssign &, HasCopyAssign &))); |
| 3075 |
static_assert((__is_assignable(HasCopyAssign &, const HasCopyAssign &))); |
| 3076 |
static_assert((__is_assignable(HasCopyAssign &, HasCopyAssign &&))); |
| 3077 |
static_assert((__is_assignable(TrivialMoveButNotCopy &, |
| 3078 |
TrivialMoveButNotCopy &))); |
| 3079 |
static_assert((__is_assignable(TrivialMoveButNotCopy &, |
| 3080 |
const TrivialMoveButNotCopy &))); |
| 3081 |
static_assert(!(__is_assignable(AllDeleted, |
| 3082 |
const AllDeleted &))); |
| 3083 |
static_assert(!(__is_assignable(AllDeleted, |
| 3084 |
AllDeleted &&))); |
| 3085 |
static_assert((__is_assignable(ExtDefaulted, |
| 3086 |
const ExtDefaulted &))); |
| 3087 |
static_assert((__is_assignable(ExtDefaulted, |
| 3088 |
ExtDefaulted &&))); |
| 3089 |
|
| 3090 |
static_assert((__is_assignable(HasDefaultTrivialCopyAssign &, |
| 3091 |
HasDefaultTrivialCopyAssign &))); |
| 3092 |
static_assert((__is_assignable(HasDefaultTrivialCopyAssign &, |
| 3093 |
const HasDefaultTrivialCopyAssign &))); |
| 3094 |
static_assert((__is_assignable(TrivialMoveButNotCopy &, |
| 3095 |
TrivialMoveButNotCopy))); |
| 3096 |
static_assert((__is_assignable(TrivialMoveButNotCopy &, |
| 3097 |
TrivialMoveButNotCopy &&))); |
| 3098 |
|
| 3099 |
static_assert(__is_assignable(ACompleteType, ACompleteType)); |
| 3100 |
static_assert(!__is_assignable(AnIncompleteType, AnIncompleteType)); // expected-error {{incomplete type}} |
| 3101 |
static_assert(!__is_assignable(AnIncompleteType[], AnIncompleteType[])); |
| 3102 |
static_assert(!__is_assignable(AnIncompleteType[1], AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 3103 |
static_assert(!__is_assignable(void, void)); |
| 3104 |
static_assert(!__is_assignable(const volatile void, const volatile void)); |
| 3105 |
|
| 3106 |
static_assert(!__is_assignable(AllPrivate, AllPrivate)); |
| 3107 |
// Make sure we don't emit "'operator=' is a private member" in SFINAE context. |
| 3108 |
static_assert(!is_assignable_sfinae<AllPrivate, AllPrivate>()); |
| 3109 |
} |
| 3110 |
|
| 3111 |
void constructible_checks() { |
| 3112 |
static_assert(__is_constructible(HasNoThrowConstructorWithArgs)); |
| 3113 |
static_assert(!__is_nothrow_constructible(HasNoThrowConstructorWithArgs)); // MSVC doesn't look into default args and gets this wrong. |
| 3114 |
|
| 3115 |
static_assert(__is_constructible(HasNoThrowConstructorWithArgs, HasCons)); |
| 3116 |
static_assert(__is_nothrow_constructible(HasNoThrowConstructorWithArgs, HasCons)); |
| 3117 |
|
| 3118 |
static_assert(__is_constructible(NonTrivialDefault)); |
| 3119 |
static_assert(!__is_nothrow_constructible(NonTrivialDefault)); |
| 3120 |
|
| 3121 |
static_assert(__is_constructible(int)); |
| 3122 |
static_assert(__is_nothrow_constructible(int)); |
| 3123 |
|
| 3124 |
static_assert(!__is_constructible(NonPOD)); |
| 3125 |
static_assert(!__is_nothrow_constructible(NonPOD)); |
| 3126 |
|
| 3127 |
static_assert(__is_constructible(NonPOD, int)); |
| 3128 |
static_assert(!__is_nothrow_constructible(NonPOD, int)); |
| 3129 |
|
| 3130 |
// PR19178 |
| 3131 |
static_assert(!__is_constructible(Abstract)); |
| 3132 |
static_assert(!__is_nothrow_constructible(Abstract)); |
| 3133 |
|
| 3134 |
// PR20228 |
| 3135 |
static_assert(__is_constructible(VariadicCtor, |
| 3136 |
int, int, int, int, int, int, int, int, int)); |
| 3137 |
|
| 3138 |
// PR25513 |
| 3139 |
static_assert(!__is_constructible(int(int))); |
| 3140 |
static_assert(__is_constructible(int const &, long)); |
| 3141 |
|
| 3142 |
static_assert(__is_constructible(ACompleteType)); |
| 3143 |
static_assert(__is_nothrow_constructible(ACompleteType)); |
| 3144 |
static_assert(!__is_constructible(AnIncompleteType)); // expected-error {{incomplete type}} |
| 3145 |
static_assert(!__is_nothrow_constructible(AnIncompleteType)); // expected-error {{incomplete type}} |
| 3146 |
static_assert(!__is_constructible(AnIncompleteType[])); |
| 3147 |
static_assert(!__is_nothrow_constructible(AnIncompleteType[])); |
| 3148 |
static_assert(!__is_constructible(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 3149 |
static_assert(!__is_nothrow_constructible(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 3150 |
static_assert(!__is_constructible(void)); |
| 3151 |
static_assert(!__is_nothrow_constructible(void)); |
| 3152 |
static_assert(!__is_constructible(const volatile void)); |
| 3153 |
static_assert(!__is_nothrow_constructible(const volatile void)); |
| 3154 |
} |
| 3155 |
|
| 3156 |
// Instantiation of __is_trivially_constructible |
| 3157 |
template<typename T, typename ...Args> |
| 3158 |
struct is_trivially_constructible { |
| 3159 |
static const bool value = __is_trivially_constructible(T, Args...); |
| 3160 |
}; |
| 3161 |
|
| 3162 |
void is_trivially_constructible_test() { |
| 3163 |
static_assert((is_trivially_constructible<int>::value)); |
| 3164 |
static_assert((is_trivially_constructible<int, int>::value)); |
| 3165 |
static_assert((is_trivially_constructible<int, float>::value)); |
| 3166 |
static_assert((is_trivially_constructible<int, int&>::value)); |
| 3167 |
static_assert((is_trivially_constructible<int, const int&>::value)); |
| 3168 |
static_assert((is_trivially_constructible<int, int>::value)); |
| 3169 |
static_assert((is_trivially_constructible<HasCopyAssign, HasCopyAssign>::value)); |
| 3170 |
static_assert((is_trivially_constructible<HasCopyAssign, const HasCopyAssign&>::value)); |
| 3171 |
static_assert((is_trivially_constructible<HasCopyAssign, HasCopyAssign&&>::value)); |
| 3172 |
static_assert((is_trivially_constructible<HasCopyAssign>::value)); |
| 3173 |
static_assert((is_trivially_constructible<NonTrivialDefault, |
| 3174 |
const NonTrivialDefault&>::value)); |
| 3175 |
static_assert((is_trivially_constructible<NonTrivialDefault, |
| 3176 |
NonTrivialDefault&&>::value)); |
| 3177 |
|
| 3178 |
static_assert(!(is_trivially_constructible<int, int*>::value)); |
| 3179 |
static_assert(!(is_trivially_constructible<NonTrivialDefault>::value)); |
| 3180 |
static_assert(!(is_trivially_constructible<ThreeArgCtor, int*, char*, int&>::value)); |
| 3181 |
static_assert(!(is_trivially_constructible<Abstract>::value)); // PR19178 |
| 3182 |
|
| 3183 |
static_assert(__is_trivially_constructible(ACompleteType)); |
| 3184 |
static_assert(!__is_trivially_constructible(AnIncompleteType)); // expected-error {{incomplete type}} |
| 3185 |
static_assert(!__is_trivially_constructible(AnIncompleteType[])); |
| 3186 |
static_assert(!__is_trivially_constructible(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 3187 |
static_assert(!__is_trivially_constructible(void)); |
| 3188 |
static_assert(!__is_trivially_constructible(const volatile void)); |
| 3189 |
} |
| 3190 |
|
| 3191 |
template <class T, class RefType = T &> |
| 3192 |
struct ConvertsToRef { |
| 3193 |
operator RefType() const { return static_cast<RefType>(obj); } |
| 3194 |
mutable T obj = 42; |
| 3195 |
}; |
| 3196 |
template <class T, class RefType = T &> |
| 3197 |
class ConvertsToRefPrivate { |
| 3198 |
operator RefType() const { return static_cast<RefType>(obj); } |
| 3199 |
mutable T obj = 42; |
| 3200 |
}; |
| 3201 |
|
| 3202 |
|
| 3203 |
void reference_binds_to_temporary_checks() { |
| 3204 |
static_assert(!(__reference_binds_to_temporary(int &, int &))); |
| 3205 |
static_assert(!(__reference_binds_to_temporary(int &, int &&))); |
| 3206 |
|
| 3207 |
static_assert(!(__reference_binds_to_temporary(int const &, int &))); |
| 3208 |
static_assert(!(__reference_binds_to_temporary(int const &, int const &))); |
| 3209 |
static_assert(!(__reference_binds_to_temporary(int const &, int &&))); |
| 3210 |
|
| 3211 |
static_assert(!(__reference_binds_to_temporary(int &, long &))); // doesn't construct |
| 3212 |
static_assert((__reference_binds_to_temporary(int const &, long &))); |
| 3213 |
static_assert((__reference_binds_to_temporary(int const &, long &&))); |
| 3214 |
static_assert((__reference_binds_to_temporary(int &&, long &))); |
| 3215 |
|
| 3216 |
using LRef = ConvertsToRef<int, int &>; |
| 3217 |
using RRef = ConvertsToRef<int, int &&>; |
| 3218 |
using CLRef = ConvertsToRef<int, const int &>; |
| 3219 |
using LongRef = ConvertsToRef<long, long &>; |
| 3220 |
static_assert((__is_constructible(int &, LRef))); |
| 3221 |
static_assert(!(__reference_binds_to_temporary(int &, LRef))); |
| 3222 |
|
| 3223 |
static_assert((__is_constructible(int &&, RRef))); |
| 3224 |
static_assert(!(__reference_binds_to_temporary(int &&, RRef))); |
| 3225 |
|
| 3226 |
static_assert((__is_constructible(int const &, CLRef))); |
| 3227 |
static_assert(!(__reference_binds_to_temporary(int &&, CLRef))); |
| 3228 |
|
| 3229 |
static_assert((__is_constructible(int const &, LongRef))); |
| 3230 |
static_assert((__reference_binds_to_temporary(int const &, LongRef))); |
| 3231 |
static_assert(!__reference_binds_to_temporary(int const &, ConvertsToRefPrivate<long, long &>)); |
| 3232 |
|
| 3233 |
|
| 3234 |
// Test that it doesn't accept non-reference types as input. |
| 3235 |
static_assert(!(__reference_binds_to_temporary(int, long))); |
| 3236 |
|
| 3237 |
static_assert((__reference_binds_to_temporary(const int &, long))); |
| 3238 |
|
| 3239 |
// Test that function references are never considered bound to temporaries. |
| 3240 |
static_assert(!__reference_binds_to_temporary(void(&)(), void())); |
| 3241 |
static_assert(!__reference_binds_to_temporary(void(&&)(), void())); |
| 3242 |
} |
| 3243 |
|
| 3244 |
|
| 3245 |
struct ExplicitConversionRvalueRef { |
| 3246 |
operator int(); |
| 3247 |
explicit operator int&&(); |
| 3248 |
}; |
| 3249 |
|
| 3250 |
struct ExplicitConversionRef { |
| 3251 |
operator int(); |
| 3252 |
explicit operator int&(); |
| 3253 |
}; |
| 3254 |
|
| 3255 |
struct NonMovable { |
| 3256 |
NonMovable(NonMovable&&) = delete; |
| 3257 |
}; |
| 3258 |
|
| 3259 |
struct ConvertsFromNonMovable { |
| 3260 |
ConvertsFromNonMovable(NonMovable); |
| 3261 |
}; |
| 3262 |
|
| 3263 |
void reference_constructs_from_temporary_checks() { |
| 3264 |
static_assert(!__reference_constructs_from_temporary(int &, int &)); |
| 3265 |
static_assert(!__reference_constructs_from_temporary(int &, int &&)); |
| 3266 |
|
| 3267 |
static_assert(!__reference_constructs_from_temporary(int const &, int &)); |
| 3268 |
static_assert(!__reference_constructs_from_temporary(int const &, int const &)); |
| 3269 |
static_assert(!__reference_constructs_from_temporary(int const &, int &&)); |
| 3270 |
|
| 3271 |
static_assert(!__reference_constructs_from_temporary(int &, long &)); // doesn't construct |
| 3272 |
|
| 3273 |
static_assert(__reference_constructs_from_temporary(int const &, long &)); |
| 3274 |
static_assert(__reference_constructs_from_temporary(int const &, long &&)); |
| 3275 |
static_assert(__reference_constructs_from_temporary(int &&, long &)); |
| 3276 |
|
| 3277 |
using LRef = ConvertsToRef<int, int &>; |
| 3278 |
using RRef = ConvertsToRef<int, int &&>; |
| 3279 |
using CLRef = ConvertsToRef<int, const int &>; |
| 3280 |
using LongRef = ConvertsToRef<long, long &>; |
| 3281 |
static_assert(__is_constructible(int &, LRef)); |
| 3282 |
static_assert(!__reference_constructs_from_temporary(int &, LRef)); |
| 3283 |
|
| 3284 |
static_assert(__is_constructible(int &&, RRef)); |
| 3285 |
static_assert(!__reference_constructs_from_temporary(int &&, RRef)); |
| 3286 |
|
| 3287 |
static_assert(__is_constructible(int const &, CLRef)); |
| 3288 |
static_assert(!__reference_constructs_from_temporary(int &&, CLRef)); |
| 3289 |
|
| 3290 |
static_assert(__is_constructible(int const &, LongRef)); |
| 3291 |
static_assert(__reference_constructs_from_temporary(int const &, LongRef)); |
| 3292 |
static_assert(!__reference_constructs_from_temporary(int const &, ConvertsToRefPrivate<long, long &>)); |
| 3293 |
|
| 3294 |
|
| 3295 |
// Test that it doesn't accept non-reference types as input. |
| 3296 |
static_assert(!__reference_constructs_from_temporary(int, long)); |
| 3297 |
|
| 3298 |
static_assert(__reference_constructs_from_temporary(const int &, long)); |
| 3299 |
|
| 3300 |
// Test that function references are never considered bound to temporaries. |
| 3301 |
static_assert(!__reference_constructs_from_temporary(void(&&)(), void())); |
| 3302 |
static_assert(!__reference_constructs_from_temporary(void(&)(), void())); |
| 3303 |
|
| 3304 |
// LWG3819: reference_meows_from_temporary should not use is_meowible |
| 3305 |
static_assert(__reference_constructs_from_temporary(ConvertsFromNonMovable&&, NonMovable) == __cplusplus >= 201703L); |
| 3306 |
// For scalar types, cv-qualifications are dropped first for prvalues. |
| 3307 |
static_assert(__reference_constructs_from_temporary(int&&, const int)); |
| 3308 |
static_assert(__reference_constructs_from_temporary(int&&, volatile int)); |
| 3309 |
|
| 3310 |
// Additional checks |
| 3311 |
static_assert(__reference_constructs_from_temporary(POD const&, Derives)); |
| 3312 |
static_assert(__reference_constructs_from_temporary(int&&, int)); |
| 3313 |
static_assert(__reference_constructs_from_temporary(const int&, int)); |
| 3314 |
static_assert(!__reference_constructs_from_temporary(int&&, int&&)); |
| 3315 |
static_assert(!__reference_constructs_from_temporary(const int&, int&&)); |
| 3316 |
static_assert(__reference_constructs_from_temporary(int&&, long&&)); |
| 3317 |
static_assert(__reference_constructs_from_temporary(int&&, long)); |
| 3318 |
|
| 3319 |
|
| 3320 |
static_assert(!__reference_constructs_from_temporary(int&, ExplicitConversionRef)); |
| 3321 |
static_assert(!__reference_constructs_from_temporary(const int&, ExplicitConversionRef)); |
| 3322 |
static_assert(!__reference_constructs_from_temporary(int&&, ExplicitConversionRvalueRef)); |
| 3323 |
|
| 3324 |
|
| 3325 |
} |
| 3326 |
|
| 3327 |
template<typename A, typename B, bool result = __reference_converts_from_temporary(A, B)> |
| 3328 |
static constexpr bool reference_converts_from_temporary_sfinae() { return result; } |
| 3329 |
|
| 3330 |
void reference_converts_from_temporary_checks() { |
| 3331 |
static_assert(!__reference_converts_from_temporary(int &, int &)); |
| 3332 |
static_assert(!__reference_converts_from_temporary(int &, int &&)); |
| 3333 |
|
| 3334 |
static_assert(!__reference_converts_from_temporary(int const &, int &)); |
| 3335 |
static_assert(!__reference_converts_from_temporary(int const &, int const &)); |
| 3336 |
static_assert(!__reference_converts_from_temporary(int const &, int &&)); |
| 3337 |
|
| 3338 |
static_assert(!__reference_converts_from_temporary(int &, long &)); // doesn't construct |
| 3339 |
|
| 3340 |
static_assert(__reference_converts_from_temporary(int const &, long &)); |
| 3341 |
static_assert(__reference_converts_from_temporary(int const &, long &&)); |
| 3342 |
static_assert(__reference_converts_from_temporary(int &&, long &)); |
| 3343 |
|
| 3344 |
using LRef = ConvertsToRef<int, int &>; |
| 3345 |
using RRef = ConvertsToRef<int, int &&>; |
| 3346 |
using CLRef = ConvertsToRef<int, const int &>; |
| 3347 |
using LongRef = ConvertsToRef<long, long &>; |
| 3348 |
static_assert(__is_constructible(int &, LRef)); |
| 3349 |
static_assert(!__reference_converts_from_temporary(int &, LRef)); |
| 3350 |
|
| 3351 |
static_assert(__is_constructible(int &&, RRef)); |
| 3352 |
static_assert(!__reference_converts_from_temporary(int &&, RRef)); |
| 3353 |
|
| 3354 |
static_assert(__is_constructible(int const &, CLRef)); |
| 3355 |
static_assert(!__reference_converts_from_temporary(int &&, CLRef)); |
| 3356 |
|
| 3357 |
static_assert(__is_constructible(int const &, LongRef)); |
| 3358 |
static_assert(__reference_converts_from_temporary(int const &, LongRef)); |
| 3359 |
static_assert(!__reference_converts_from_temporary(int const &, ConvertsToRefPrivate<long, long &>)); |
| 3360 |
|
| 3361 |
|
| 3362 |
// Test that it doesn't accept non-reference types as input. |
| 3363 |
static_assert(!__reference_converts_from_temporary(int, long)); |
| 3364 |
|
| 3365 |
static_assert(__reference_converts_from_temporary(const int &, long)); |
| 3366 |
|
| 3367 |
// Test that function references are never considered bound to temporaries. |
| 3368 |
static_assert(!__reference_converts_from_temporary(void(&)(), void())); |
| 3369 |
static_assert(!__reference_converts_from_temporary(void(&&)(), void())); |
| 3370 |
|
| 3371 |
// LWG3819: reference_meows_from_temporary should not use is_meowible |
| 3372 |
static_assert(__reference_converts_from_temporary(ConvertsFromNonMovable&&, NonMovable) == __cplusplus >= 201703L); |
| 3373 |
// For scalar types, cv-qualifications are dropped first for prvalues. |
| 3374 |
static_assert(__reference_converts_from_temporary(int&&, const int)); |
| 3375 |
static_assert(__reference_converts_from_temporary(int&&, volatile int)); |
| 3376 |
|
| 3377 |
// Additional checks |
| 3378 |
static_assert(__reference_converts_from_temporary(POD const&, Derives)); |
| 3379 |
static_assert(__reference_converts_from_temporary(int&&, int)); |
| 3380 |
static_assert(__reference_converts_from_temporary(const int&, int)); |
| 3381 |
static_assert(!__reference_converts_from_temporary(int&&, int&&)); |
| 3382 |
static_assert(!__reference_converts_from_temporary(const int&, int&&)); |
| 3383 |
static_assert(__reference_converts_from_temporary(int&&, long&&)); |
| 3384 |
static_assert(__reference_converts_from_temporary(int&&, long)); |
| 3385 |
|
| 3386 |
static_assert(!__reference_converts_from_temporary(int&, ExplicitConversionRef)); |
| 3387 |
static_assert(__reference_converts_from_temporary(const int&, ExplicitConversionRef)); |
| 3388 |
static_assert(__reference_converts_from_temporary(int&&, ExplicitConversionRvalueRef)); |
| 3389 |
|
| 3390 |
static_assert(!__reference_converts_from_temporary(AllPrivate, AllPrivate)); |
| 3391 |
// Make sure we don't emit "calling a private constructor" in SFINAE context. |
| 3392 |
static_assert(!reference_converts_from_temporary_sfinae<AllPrivate, AllPrivate>()); |
| 3393 |
} |
| 3394 |
|
| 3395 |
void array_rank() { |
| 3396 |
static_assert(__array_rank(IntAr) == 1); |
| 3397 |
static_assert(__array_rank(ConstIntArAr) == 2); |
| 3398 |
} |
| 3399 |
|
| 3400 |
void array_extent() { |
| 3401 |
static_assert(__array_extent(IntAr, 0) == 10); |
| 3402 |
static_assert(__array_extent(ConstIntArAr, 0) == 4); |
| 3403 |
static_assert(__array_extent(ConstIntArAr, 1) == 10); |
| 3404 |
} |
| 3405 |
|
| 3406 |
void is_destructible_test() { |
| 3407 |
static_assert(__is_destructible(int)); |
| 3408 |
static_assert(__is_destructible(int[2])); |
| 3409 |
static_assert(!__is_destructible(int[])); |
| 3410 |
static_assert(!__is_destructible(void)); |
| 3411 |
static_assert(__is_destructible(int &)); |
| 3412 |
static_assert(__is_destructible(HasDest)); |
| 3413 |
static_assert(!__is_destructible(AllPrivate)); |
| 3414 |
static_assert(__is_destructible(SuperNonTrivialStruct)); |
| 3415 |
static_assert(__is_destructible(AllDefaulted)); |
| 3416 |
static_assert(!__is_destructible(AllDeleted)); |
| 3417 |
static_assert(__is_destructible(ThrowingDtor)); |
| 3418 |
static_assert(__is_destructible(NoThrowDtor)); |
| 3419 |
|
| 3420 |
static_assert(__is_destructible(ACompleteType)); |
| 3421 |
static_assert(!__is_destructible(AnIncompleteType)); // expected-error {{incomplete type}} |
| 3422 |
static_assert(!__is_destructible(AnIncompleteType[])); |
| 3423 |
static_assert(!__is_destructible(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 3424 |
static_assert(!__is_destructible(void)); |
| 3425 |
static_assert(!__is_destructible(const volatile void)); |
| 3426 |
} |
| 3427 |
|
| 3428 |
void is_nothrow_destructible_test() { |
| 3429 |
static_assert(__is_nothrow_destructible(int)); |
| 3430 |
static_assert(__is_nothrow_destructible(int[2])); |
| 3431 |
static_assert(!__is_nothrow_destructible(int[])); |
| 3432 |
static_assert(!__is_nothrow_destructible(void)); |
| 3433 |
static_assert(__is_nothrow_destructible(int &)); |
| 3434 |
static_assert(__is_nothrow_destructible(HasDest)); |
| 3435 |
static_assert(!__is_nothrow_destructible(AllPrivate)); |
| 3436 |
static_assert(__is_nothrow_destructible(SuperNonTrivialStruct)); |
| 3437 |
static_assert(__is_nothrow_destructible(AllDefaulted)); |
| 3438 |
static_assert(!__is_nothrow_destructible(AllDeleted)); |
| 3439 |
static_assert(!__is_nothrow_destructible(ThrowingDtor)); |
| 3440 |
static_assert(__is_nothrow_destructible(NoExceptDtor)); |
| 3441 |
static_assert(__is_nothrow_destructible(NoThrowDtor)); |
| 3442 |
|
| 3443 |
static_assert(__is_nothrow_destructible(ACompleteType)); |
| 3444 |
static_assert(!__is_nothrow_destructible(AnIncompleteType)); // expected-error {{incomplete type}} |
| 3445 |
static_assert(!__is_nothrow_destructible(AnIncompleteType[])); |
| 3446 |
static_assert(!__is_nothrow_destructible(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 3447 |
static_assert(!__is_nothrow_destructible(void)); |
| 3448 |
static_assert(!__is_nothrow_destructible(const volatile void)); |
| 3449 |
} |
| 3450 |
|
| 3451 |
void is_trivially_destructible_test() { |
| 3452 |
static_assert(__is_trivially_destructible(int)); |
| 3453 |
static_assert(__is_trivially_destructible(int[2])); |
| 3454 |
static_assert(!__is_trivially_destructible(int[])); |
| 3455 |
static_assert(!__is_trivially_destructible(void)); |
| 3456 |
static_assert(__is_trivially_destructible(int &)); |
| 3457 |
static_assert(!__is_trivially_destructible(HasDest)); |
| 3458 |
static_assert(!__is_trivially_destructible(AllPrivate)); |
| 3459 |
static_assert(!__is_trivially_destructible(SuperNonTrivialStruct)); |
| 3460 |
static_assert(__is_trivially_destructible(AllDefaulted)); |
| 3461 |
static_assert(!__is_trivially_destructible(AllDeleted)); |
| 3462 |
static_assert(!__is_trivially_destructible(ThrowingDtor)); |
| 3463 |
static_assert(!__is_trivially_destructible(NoThrowDtor)); |
| 3464 |
|
| 3465 |
static_assert(__is_trivially_destructible(ACompleteType)); |
| 3466 |
static_assert(!__is_trivially_destructible(AnIncompleteType)); // expected-error {{incomplete type}} |
| 3467 |
static_assert(!__is_trivially_destructible(AnIncompleteType[])); |
| 3468 |
static_assert(!__is_trivially_destructible(AnIncompleteType[1])); // expected-error {{incomplete type}} |
| 3469 |
static_assert(!__is_trivially_destructible(void)); |
| 3470 |
static_assert(!__is_trivially_destructible(const volatile void)); |
| 3471 |
} |
| 3472 |
|
| 3473 |
static_assert(!__has_unique_object_representations(void), "void is never unique"); |
| 3474 |
static_assert(!__has_unique_object_representations(const void), "void is never unique"); |
| 3475 |
static_assert(!__has_unique_object_representations(volatile void), "void is never unique"); |
| 3476 |
static_assert(!__has_unique_object_representations(const volatile void), "void is never unique"); |
| 3477 |
|
| 3478 |
static_assert(__has_unique_object_representations(int), "integrals are"); |
| 3479 |
static_assert(__has_unique_object_representations(const int), "integrals are"); |
| 3480 |
static_assert(__has_unique_object_representations(volatile int), "integrals are"); |
| 3481 |
static_assert(__has_unique_object_representations(const volatile int), "integrals are"); |
| 3482 |
|
| 3483 |
static_assert(__has_unique_object_representations(void *), "as are pointers"); |
| 3484 |
static_assert(__has_unique_object_representations(const void *), "as are pointers"); |
| 3485 |
static_assert(__has_unique_object_representations(volatile void *), "are pointers"); |
| 3486 |
static_assert(__has_unique_object_representations(const volatile void *), "as are pointers"); |
| 3487 |
|
| 3488 |
static_assert(__has_unique_object_representations(int *), "as are pointers"); |
| 3489 |
static_assert(__has_unique_object_representations(const int *), "as are pointers"); |
| 3490 |
static_assert(__has_unique_object_representations(volatile int *), "as are pointers"); |
| 3491 |
static_assert(__has_unique_object_representations(const volatile int *), "as are pointers"); |
| 3492 |
|
| 3493 |
class C {}; |
| 3494 |
using FP = int (*)(int); |
| 3495 |
using PMF = int (C::*)(int); |
| 3496 |
using PMD = int C::*; |
| 3497 |
|
| 3498 |
static_assert(__has_unique_object_representations(FP), "even function pointers"); |
| 3499 |
static_assert(__has_unique_object_representations(const FP), "even function pointers"); |
| 3500 |
static_assert(__has_unique_object_representations(volatile FP), "even function pointers"); |
| 3501 |
static_assert(__has_unique_object_representations(const volatile FP), "even function pointers"); |
| 3502 |
|
| 3503 |
static_assert(__has_unique_object_representations(PMF), "and pointer to members"); |
| 3504 |
static_assert(__has_unique_object_representations(const PMF), "and pointer to members"); |
| 3505 |
static_assert(__has_unique_object_representations(volatile PMF), "and pointer to members"); |
| 3506 |
static_assert(__has_unique_object_representations(const volatile PMF), "and pointer to members"); |
| 3507 |
|
| 3508 |
static_assert(__has_unique_object_representations(PMD), "and pointer to members"); |
| 3509 |
static_assert(__has_unique_object_representations(const PMD), "and pointer to members"); |
| 3510 |
static_assert(__has_unique_object_representations(volatile PMD), "and pointer to members"); |
| 3511 |
static_assert(__has_unique_object_representations(const volatile PMD), "and pointer to members"); |
| 3512 |
|
| 3513 |
static_assert(__has_unique_object_representations(bool), "yes, all integral types"); |
| 3514 |
static_assert(__has_unique_object_representations(char), "yes, all integral types"); |
| 3515 |
static_assert(__has_unique_object_representations(signed char), "yes, all integral types"); |
| 3516 |
static_assert(__has_unique_object_representations(unsigned char), "yes, all integral types"); |
| 3517 |
static_assert(__has_unique_object_representations(short), "yes, all integral types"); |
| 3518 |
static_assert(__has_unique_object_representations(unsigned short), "yes, all integral types"); |
| 3519 |
static_assert(__has_unique_object_representations(int), "yes, all integral types"); |
| 3520 |
static_assert(__has_unique_object_representations(unsigned int), "yes, all integral types"); |
| 3521 |
static_assert(__has_unique_object_representations(long), "yes, all integral types"); |
| 3522 |
static_assert(__has_unique_object_representations(unsigned long), "yes, all integral types"); |
| 3523 |
static_assert(__has_unique_object_representations(long long), "yes, all integral types"); |
| 3524 |
static_assert(__has_unique_object_representations(unsigned long long), "yes, all integral types"); |
| 3525 |
static_assert(__has_unique_object_representations(wchar_t), "yes, all integral types"); |
| 3526 |
static_assert(__has_unique_object_representations(char16_t), "yes, all integral types"); |
| 3527 |
static_assert(__has_unique_object_representations(char32_t), "yes, all integral types"); |
| 3528 |
|
| 3529 |
static_assert(!__has_unique_object_representations(void), "but not void!"); |
| 3530 |
static_assert(!__has_unique_object_representations(decltype(nullptr)), "or nullptr_t"); |
| 3531 |
static_assert(!__has_unique_object_representations(float), "definitely not Floating Point"); |
| 3532 |
static_assert(!__has_unique_object_representations(double), "definitely not Floating Point"); |
| 3533 |
static_assert(!__has_unique_object_representations(long double), "definitely not Floating Point"); |
| 3534 |
|
| 3535 |
|
| 3536 |
static_assert(!__has_unique_object_representations(AnIncompleteType[])); |
| 3537 |
//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}} |
| 3538 |
static_assert(!__has_unique_object_representations(AnIncompleteType[][1])); |
| 3539 |
//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}} |
| 3540 |
static_assert(!__has_unique_object_representations(AnIncompleteType[1])); |
| 3541 |
//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}} |
| 3542 |
static_assert(!__has_unique_object_representations(AnIncompleteType)); |
| 3543 |
//expected-error@-1 {{incomplete type 'AnIncompleteType' used in type trait expression}} |
| 3544 |
|
| 3545 |
struct NoPadding { |
| 3546 |
int a; |
| 3547 |
int b; |
| 3548 |
}; |
| 3549 |
|
| 3550 |
static_assert(__has_unique_object_representations(NoPadding), "types without padding are"); |
| 3551 |
|
| 3552 |
struct InheritsFromNoPadding : NoPadding { |
| 3553 |
int c; |
| 3554 |
int d; |
| 3555 |
}; |
| 3556 |
|
| 3557 |
static_assert(__has_unique_object_representations(InheritsFromNoPadding), "types without padding are"); |
| 3558 |
|
| 3559 |
struct VirtuallyInheritsFromNoPadding : virtual NoPadding { |
| 3560 |
int c; |
| 3561 |
int d; |
| 3562 |
}; |
| 3563 |
|
| 3564 |
static_assert(!__has_unique_object_representations(VirtuallyInheritsFromNoPadding), "No virtual inheritance"); |
| 3565 |
|
| 3566 |
struct Padding { |
| 3567 |
char a; |
| 3568 |
int b; |
| 3569 |
}; |
| 3570 |
|
| 3571 |
//static_assert(!__has_unique_object_representations(Padding), "but not with padding"); |
| 3572 |
|
| 3573 |
struct InheritsFromPadding : Padding { |
| 3574 |
int c; |
| 3575 |
int d; |
| 3576 |
}; |
| 3577 |
|
| 3578 |
static_assert(!__has_unique_object_representations(InheritsFromPadding), "or its subclasses"); |
| 3579 |
|
| 3580 |
struct TailPadding { |
| 3581 |
int a; |
| 3582 |
char b; |
| 3583 |
}; |
| 3584 |
|
| 3585 |
static_assert(!__has_unique_object_representations(TailPadding), "even at the end"); |
| 3586 |
|
| 3587 |
struct TinyStruct { |
| 3588 |
char a; |
| 3589 |
}; |
| 3590 |
|
| 3591 |
static_assert(__has_unique_object_representations(TinyStruct), "Should be no padding"); |
| 3592 |
|
| 3593 |
struct InheritsFromTinyStruct : TinyStruct { |
| 3594 |
int b; |
| 3595 |
}; |
| 3596 |
|
| 3597 |
static_assert(!__has_unique_object_representations(InheritsFromTinyStruct), "Inherit causes padding"); |
| 3598 |
|
| 3599 |
union NoPaddingUnion { |
| 3600 |
int a; |
| 3601 |
unsigned int b; |
| 3602 |
}; |
| 3603 |
|
| 3604 |
static_assert(__has_unique_object_representations(NoPaddingUnion), "unions follow the same rules as structs"); |
| 3605 |
|
| 3606 |
union PaddingUnion { |
| 3607 |
int a; |
| 3608 |
long long b; |
| 3609 |
}; |
| 3610 |
|
| 3611 |
static_assert(!__has_unique_object_representations(PaddingUnion), "unions follow the same rules as structs"); |
| 3612 |
|
| 3613 |
struct NotTriviallyCopyable { |
| 3614 |
int x; |
| 3615 |
NotTriviallyCopyable(const NotTriviallyCopyable &) {} |
| 3616 |
}; |
| 3617 |
|
| 3618 |
static_assert(!__has_unique_object_representations(NotTriviallyCopyable), "must be trivially copyable"); |
| 3619 |
|
| 3620 |
struct HasNonUniqueMember { |
| 3621 |
float x; |
| 3622 |
}; |
| 3623 |
|
| 3624 |
static_assert(!__has_unique_object_representations(HasNonUniqueMember), "all members must be unique"); |
| 3625 |
|
| 3626 |
enum ExampleEnum { xExample, |
| 3627 |
yExample }; |
| 3628 |
enum LLEnum : long long { xLongExample, |
| 3629 |
yLongExample }; |
| 3630 |
|
| 3631 |
static_assert(__has_unique_object_representations(ExampleEnum), "Enums are integrals, so unique!"); |
| 3632 |
static_assert(__has_unique_object_representations(LLEnum), "Enums are integrals, so unique!"); |
| 3633 |
|
| 3634 |
enum class ExampleEnumClass { xExample, |
| 3635 |
yExample }; |
| 3636 |
enum class LLEnumClass : long long { xLongExample, |
| 3637 |
yLongExample }; |
| 3638 |
|
| 3639 |
static_assert(__has_unique_object_representations(ExampleEnumClass), "Enums are integrals, so unique!"); |
| 3640 |
static_assert(__has_unique_object_representations(LLEnumClass), "Enums are integrals, so unique!"); |
| 3641 |
|
| 3642 |
// because references aren't trivially copyable. |
| 3643 |
static_assert(!__has_unique_object_representations(int &), "No references!"); |
| 3644 |
static_assert(!__has_unique_object_representations(const int &), "No references!"); |
| 3645 |
static_assert(!__has_unique_object_representations(volatile int &), "No references!"); |
| 3646 |
static_assert(!__has_unique_object_representations(const volatile int &), "No references!"); |
| 3647 |
static_assert(!__has_unique_object_representations(Empty), "No empty types!"); |
| 3648 |
static_assert(!__has_unique_object_representations(EmptyUnion), "No empty types!"); |
| 3649 |
|
| 3650 |
class Compressed : Empty { |
| 3651 |
int x; |
| 3652 |
}; |
| 3653 |
|
| 3654 |
static_assert(__has_unique_object_representations(Compressed), "But inheriting from one is ok"); |
| 3655 |
|
| 3656 |
class EmptyInheritor : Compressed {}; |
| 3657 |
|
| 3658 |
static_assert(__has_unique_object_representations(EmptyInheritor), "As long as the base has items, empty is ok"); |
| 3659 |
|
| 3660 |
class Dynamic { |
| 3661 |
virtual void A(); |
| 3662 |
int i; |
| 3663 |
}; |
| 3664 |
|
| 3665 |
static_assert(!__has_unique_object_representations(Dynamic), "Dynamic types are not valid"); |
| 3666 |
|
| 3667 |
class InheritsDynamic : Dynamic { |
| 3668 |
int j; |
| 3669 |
}; |
| 3670 |
|
| 3671 |
static_assert(!__has_unique_object_representations(InheritsDynamic), "Dynamic types are not valid"); |
| 3672 |
|
| 3673 |
static_assert(__has_unique_object_representations(int[42]), "Arrays are fine, as long as their value type is"); |
| 3674 |
static_assert(__has_unique_object_representations(int[]), "Arrays are fine, as long as their value type is"); |
| 3675 |
static_assert(__has_unique_object_representations(int[][42]), "Arrays are fine, as long as their value type is"); |
| 3676 |
static_assert(!__has_unique_object_representations(double[42]), "So no array of doubles!"); |
| 3677 |
static_assert(!__has_unique_object_representations(double[]), "So no array of doubles!"); |
| 3678 |
static_assert(!__has_unique_object_representations(double[][42]), "So no array of doubles!"); |
| 3679 |
|
| 3680 |
struct __attribute__((aligned(16))) WeirdAlignment { |
| 3681 |
int i; |
| 3682 |
}; |
| 3683 |
union __attribute__((aligned(16))) WeirdAlignmentUnion { |
| 3684 |
int i; |
| 3685 |
}; |
| 3686 |
static_assert(!__has_unique_object_representations(WeirdAlignment), "Alignment causes padding"); |
| 3687 |
static_assert(!__has_unique_object_representations(WeirdAlignmentUnion), "Alignment causes padding"); |
| 3688 |
static_assert(!__has_unique_object_representations(WeirdAlignment[42]), "Also no arrays that have padding"); |
| 3689 |
|
| 3690 |
struct __attribute__((packed)) PackedNoPadding1 { |
| 3691 |
short i; |
| 3692 |
int j; |
| 3693 |
}; |
| 3694 |
struct __attribute__((packed)) PackedNoPadding2 { |
| 3695 |
int j; |
| 3696 |
short i; |
| 3697 |
}; |
| 3698 |
static_assert(__has_unique_object_representations(PackedNoPadding1), "Packed structs have no padding"); |
| 3699 |
static_assert(__has_unique_object_representations(PackedNoPadding2), "Packed structs have no padding"); |
| 3700 |
|
| 3701 |
static_assert(!__has_unique_object_representations(int(int)), "Functions are not unique"); |
| 3702 |
static_assert(!__has_unique_object_representations(int(int) const), "Functions are not unique"); |
| 3703 |
static_assert(!__has_unique_object_representations(int(int) volatile), "Functions are not unique"); |
| 3704 |
static_assert(!__has_unique_object_representations(int(int) const volatile), "Functions are not unique"); |
| 3705 |
static_assert(!__has_unique_object_representations(int(int) &), "Functions are not unique"); |
| 3706 |
static_assert(!__has_unique_object_representations(int(int) const &), "Functions are not unique"); |
| 3707 |
static_assert(!__has_unique_object_representations(int(int) volatile &), "Functions are not unique"); |
| 3708 |
static_assert(!__has_unique_object_representations(int(int) const volatile &), "Functions are not unique"); |
| 3709 |
static_assert(!__has_unique_object_representations(int(int) &&), "Functions are not unique"); |
| 3710 |
static_assert(!__has_unique_object_representations(int(int) const &&), "Functions are not unique"); |
| 3711 |
static_assert(!__has_unique_object_representations(int(int) volatile &&), "Functions are not unique"); |
| 3712 |
static_assert(!__has_unique_object_representations(int(int) const volatile &&), "Functions are not unique"); |
| 3713 |
|
| 3714 |
static_assert(!__has_unique_object_representations(int(int, ...)), "Functions are not unique"); |
| 3715 |
static_assert(!__has_unique_object_representations(int(int, ...) const), "Functions are not unique"); |
| 3716 |
static_assert(!__has_unique_object_representations(int(int, ...) volatile), "Functions are not unique"); |
| 3717 |
static_assert(!__has_unique_object_representations(int(int, ...) const volatile), "Functions are not unique"); |
| 3718 |
static_assert(!__has_unique_object_representations(int(int, ...) &), "Functions are not unique"); |
| 3719 |
static_assert(!__has_unique_object_representations(int(int, ...) const &), "Functions are not unique"); |
| 3720 |
static_assert(!__has_unique_object_representations(int(int, ...) volatile &), "Functions are not unique"); |
| 3721 |
static_assert(!__has_unique_object_representations(int(int, ...) const volatile &), "Functions are not unique"); |
| 3722 |
static_assert(!__has_unique_object_representations(int(int, ...) &&), "Functions are not unique"); |
| 3723 |
static_assert(!__has_unique_object_representations(int(int, ...) const &&), "Functions are not unique"); |
| 3724 |
static_assert(!__has_unique_object_representations(int(int, ...) volatile &&), "Functions are not unique"); |
| 3725 |
static_assert(!__has_unique_object_representations(int(int, ...) const volatile &&), "Functions are not unique"); |
| 3726 |
|
| 3727 |
void foo(){ |
| 3728 |
static auto lambda = []() {}; |
| 3729 |
static_assert(!__has_unique_object_representations(decltype(lambda)), "Lambdas follow struct rules"); |
| 3730 |
int i; |
| 3731 |
static auto lambda2 = [i]() {}; |
| 3732 |
static_assert(__has_unique_object_representations(decltype(lambda2)), "Lambdas follow struct rules"); |
| 3733 |
} |
| 3734 |
|
| 3735 |
struct PaddedBitfield { |
| 3736 |
char c : 6; |
| 3737 |
char d : 1; |
| 3738 |
}; |
| 3739 |
|
| 3740 |
struct UnPaddedBitfield { |
| 3741 |
char c : 6; |
| 3742 |
char d : 2; |
| 3743 |
}; |
| 3744 |
|
| 3745 |
struct AlignedPaddedBitfield { |
| 3746 |
char c : 6; |
| 3747 |
__attribute__((aligned(1))) |
| 3748 |
char d : 2; |
| 3749 |
}; |
| 3750 |
|
| 3751 |
struct UnnamedBitfield { |
| 3752 |
int named : 8; |
| 3753 |
int : 24; |
| 3754 |
}; |
| 3755 |
|
| 3756 |
struct __attribute__((packed)) UnnamedBitfieldPacked { |
| 3757 |
int named : 8; |
| 3758 |
int : 24; |
| 3759 |
}; |
| 3760 |
|
| 3761 |
struct UnnamedEmptyBitfield { |
| 3762 |
int named; |
| 3763 |
int : 0; |
| 3764 |
}; |
| 3765 |
|
| 3766 |
struct UnnamedEmptyBitfieldSplit { |
| 3767 |
short named; |
| 3768 |
int : 0; |
| 3769 |
short also_named; |
| 3770 |
}; |
| 3771 |
|
| 3772 |
static_assert(!__has_unique_object_representations(PaddedBitfield), "Bitfield padding"); |
| 3773 |
static_assert(__has_unique_object_representations(UnPaddedBitfield), "Bitfield padding"); |
| 3774 |
static_assert(!__has_unique_object_representations(AlignedPaddedBitfield), "Bitfield padding"); |
| 3775 |
static_assert(!__has_unique_object_representations(UnnamedBitfield), "Bitfield padding"); |
| 3776 |
static_assert(!__has_unique_object_representations(UnnamedBitfieldPacked), "Bitfield padding"); |
| 3777 |
static_assert(__has_unique_object_representations(UnnamedEmptyBitfield), "Bitfield padding"); |
| 3778 |
static_assert(sizeof(UnnamedEmptyBitfieldSplit) != (sizeof(short) * 2), "Wrong size"); |
| 3779 |
static_assert(!__has_unique_object_representations(UnnamedEmptyBitfieldSplit), "Bitfield padding"); |
| 3780 |
|
| 3781 |
struct BoolBitfield { |
| 3782 |
bool b : 8; |
| 3783 |
}; |
| 3784 |
|
| 3785 |
static_assert(__has_unique_object_representations(BoolBitfield), "Bitfield bool"); |
| 3786 |
|
| 3787 |
struct BoolBitfield2 { |
| 3788 |
bool b : 16; |
| 3789 |
}; |
| 3790 |
|
| 3791 |
static_assert(!__has_unique_object_representations(BoolBitfield2), "Bitfield bool"); |
| 3792 |
|
| 3793 |
struct GreaterSizeBitfield { |
| 3794 |
//expected-warning@+1 {{width of bit-field 'n'}} |
| 3795 |
int n : 1024; |
| 3796 |
}; |
| 3797 |
|
| 3798 |
static_assert(sizeof(GreaterSizeBitfield) == 128, "Bitfield Size"); |
| 3799 |
static_assert(!__has_unique_object_representations(GreaterSizeBitfield), "Bitfield padding"); |
| 3800 |
|
| 3801 |
struct StructWithRef { |
| 3802 |
int &I; |
| 3803 |
}; |
| 3804 |
|
| 3805 |
static_assert(__has_unique_object_representations(StructWithRef), "References are still unique"); |
| 3806 |
|
| 3807 |
struct NotUniqueBecauseTailPadding { |
| 3808 |
int &r; |
| 3809 |
char a; |
| 3810 |
}; |
| 3811 |
struct CanBeUniqueIfNoPadding : NotUniqueBecauseTailPadding { |
| 3812 |
char b[7]; |
| 3813 |
}; |
| 3814 |
|
| 3815 |
static_assert(!__has_unique_object_representations(NotUniqueBecauseTailPadding), |
| 3816 |
"non trivial"); |
| 3817 |
// Can be unique on Itanium, since the is child class' data is 'folded' into the |
| 3818 |
// parent's tail padding. |
| 3819 |
static_assert(sizeof(CanBeUniqueIfNoPadding) != 16 || |
| 3820 |
__has_unique_object_representations(CanBeUniqueIfNoPadding), |
| 3821 |
"inherit from std layout"); |
| 3822 |
|
| 3823 |
namespace ErrorType { |
| 3824 |
struct S; //expected-note{{forward declaration of 'ErrorType::S'}} |
| 3825 |
|
| 3826 |
struct T { |
| 3827 |
S t; //expected-error{{field has incomplete type 'S'}} |
| 3828 |
}; |
| 3829 |
bool b = __has_unique_object_representations(T); |
| 3830 |
}; |
| 3831 |
|
| 3832 |
static_assert(!__has_unique_object_representations(_BitInt(7)), "BitInt:"); |
| 3833 |
static_assert(__has_unique_object_representations(_BitInt(8)), "BitInt:"); |
| 3834 |
static_assert(!__has_unique_object_representations(_BitInt(127)), "BitInt:"); |
| 3835 |
static_assert(__has_unique_object_representations(_BitInt(128)), "BitInt:"); |
| 3836 |
|
| 3837 |
namespace GH95311 { |
| 3838 |
|
| 3839 |
template <int> |
| 3840 |
class Foo { |
| 3841 |
int x; |
| 3842 |
}; |
| 3843 |
static_assert(__has_unique_object_representations(Foo<0>[])); |
| 3844 |
class Bar; // expected-note {{forward declaration of 'GH95311::Bar'}} |
| 3845 |
static_assert(__has_unique_object_representations(Bar[])); // expected-error {{incomplete type}} |
| 3846 |
|
| 3847 |
} |
| 3848 |
|
| 3849 |
namespace PR46209 { |
| 3850 |
// Foo has both a trivial assignment operator and a non-trivial one. |
| 3851 |
struct Foo { |
| 3852 |
Foo &operator=(const Foo &) & { return *this; } |
| 3853 |
Foo &operator=(const Foo &) && = default; |
| 3854 |
}; |
| 3855 |
|
| 3856 |
// Bar's copy assignment calls Foo's non-trivial assignment. |
| 3857 |
struct Bar { |
| 3858 |
Foo foo; |
| 3859 |
}; |
| 3860 |
|
| 3861 |
static_assert(!__is_trivially_assignable(Foo &, const Foo &)); |
| 3862 |
static_assert(!__is_trivially_assignable(Bar &, const Bar &)); |
| 3863 |
|
| 3864 |
// Foo2 has both a trivial assignment operator and a non-trivial one. |
| 3865 |
struct Foo2 { |
| 3866 |
Foo2 &operator=(const Foo2 &) & = default; |
| 3867 |
Foo2 &operator=(const Foo2 &) && { return *this; } |
| 3868 |
}; |
| 3869 |
|
| 3870 |
// Bar2's copy assignment calls Foo2's trivial assignment. |
| 3871 |
struct Bar2 { |
| 3872 |
Foo2 foo; |
| 3873 |
}; |
| 3874 |
|
| 3875 |
static_assert(__is_trivially_assignable(Foo2 &, const Foo2 &)); |
| 3876 |
static_assert(__is_trivially_assignable(Bar2 &, const Bar2 &)); |
| 3877 |
} |
| 3878 |
|
| 3879 |
namespace ConstClass { |
| 3880 |
struct A { |
| 3881 |
A &operator=(const A&) = default; |
| 3882 |
}; |
| 3883 |
struct B { |
| 3884 |
const A a; |
| 3885 |
}; |
| 3886 |
static_assert(!__is_trivially_assignable(B&, const B&)); |
| 3887 |
} |
| 3888 |
|
| 3889 |
namespace type_trait_expr_numargs_overflow { |
| 3890 |
// Make sure that TypeTraitExpr can store 16 bits worth of arguments. |
| 3891 |
#define T4(X) X,X,X,X |
| 3892 |
#define T16(X) T4(X),T4(X),T4(X),T4(X) |
| 3893 |
#define T64(X) T16(X),T16(X),T16(X),T16(X) |
| 3894 |
#define T256(X) T64(X),T64(X),T64(X),T64(X) |
| 3895 |
#define T1024(X) T256(X),T256(X),T256(X),T256(X) |
| 3896 |
#define T4096(X) T1024(X),T1024(X),T1024(X),T1024(X) |
| 3897 |
#define T16384(X) T4096(X),T4096(X),T4096(X),T4096(X) |
| 3898 |
#define T32768(X) T16384(X),T16384(X) |
| 3899 |
void test() { (void) __is_constructible(int, T32768(int)); } |
| 3900 |
#undef T4 |
| 3901 |
#undef T16 |
| 3902 |
#undef T64 |
| 3903 |
#undef T256 |
| 3904 |
#undef T1024 |
| 3905 |
#undef T4096 |
| 3906 |
#undef T16384 |
| 3907 |
#undef T32768 |
| 3908 |
} // namespace type_trait_expr_numargs_overflow |
| 3909 |
|
| 3910 |
namespace is_trivially_relocatable { |
| 3911 |
|
| 3912 |
static_assert(!__is_trivially_relocatable(void)); |
| 3913 |
static_assert(__is_trivially_relocatable(int)); |
| 3914 |
static_assert(__is_trivially_relocatable(int[])); |
| 3915 |
static_assert(__is_trivially_relocatable(const int)); |
| 3916 |
static_assert(__is_trivially_relocatable(volatile int)); |
| 3917 |
|
| 3918 |
enum Enum {}; |
| 3919 |
static_assert(__is_trivially_relocatable(Enum)); |
| 3920 |
static_assert(__is_trivially_relocatable(Enum[])); |
| 3921 |
|
| 3922 |
union Union {int x;}; |
| 3923 |
static_assert(__is_trivially_relocatable(Union)); |
| 3924 |
static_assert(__is_trivially_relocatable(Union[])); |
| 3925 |
|
| 3926 |
struct Trivial {}; |
| 3927 |
static_assert(__is_trivially_relocatable(Trivial)); |
| 3928 |
static_assert(__is_trivially_relocatable(const Trivial)); |
| 3929 |
static_assert(__is_trivially_relocatable(volatile Trivial)); |
| 3930 |
|
| 3931 |
static_assert(__is_trivially_relocatable(Trivial[])); |
| 3932 |
static_assert(__is_trivially_relocatable(const Trivial[])); |
| 3933 |
static_assert(__is_trivially_relocatable(volatile Trivial[])); |
| 3934 |
|
| 3935 |
static_assert(__is_trivially_relocatable(int[10])); |
| 3936 |
static_assert(__is_trivially_relocatable(const int[10])); |
| 3937 |
static_assert(__is_trivially_relocatable(volatile int[10])); |
| 3938 |
|
| 3939 |
static_assert(__is_trivially_relocatable(int[10][10])); |
| 3940 |
static_assert(__is_trivially_relocatable(const int[10][10])); |
| 3941 |
static_assert(__is_trivially_relocatable(volatile int[10][10])); |
| 3942 |
|
| 3943 |
static_assert(__is_trivially_relocatable(int[])); |
| 3944 |
static_assert(__is_trivially_relocatable(const int[])); |
| 3945 |
static_assert(__is_trivially_relocatable(volatile int[])); |
| 3946 |
|
| 3947 |
static_assert(__is_trivially_relocatable(int[][10])); |
| 3948 |
static_assert(__is_trivially_relocatable(const int[][10])); |
| 3949 |
static_assert(__is_trivially_relocatable(volatile int[][10])); |
| 3950 |
|
| 3951 |
struct Incomplete; // expected-note {{forward declaration of 'is_trivially_relocatable::Incomplete'}} |
| 3952 |
bool unused = __is_trivially_relocatable(Incomplete); // expected-error {{incomplete type}} |
| 3953 |
|
| 3954 |
struct NontrivialDtor { |
| 3955 |
~NontrivialDtor() {} |
| 3956 |
}; |
| 3957 |
static_assert(!__is_trivially_relocatable(NontrivialDtor)); |
| 3958 |
static_assert(!__is_trivially_relocatable(NontrivialDtor[])); |
| 3959 |
static_assert(!__is_trivially_relocatable(const NontrivialDtor)); |
| 3960 |
static_assert(!__is_trivially_relocatable(volatile NontrivialDtor)); |
| 3961 |
|
| 3962 |
struct NontrivialCopyCtor { |
| 3963 |
NontrivialCopyCtor(const NontrivialCopyCtor&) {} |
| 3964 |
}; |
| 3965 |
static_assert(!__is_trivially_relocatable(NontrivialCopyCtor)); |
| 3966 |
static_assert(!__is_trivially_relocatable(NontrivialCopyCtor[])); |
| 3967 |
|
| 3968 |
struct NontrivialMoveCtor { |
| 3969 |
NontrivialMoveCtor(NontrivialMoveCtor&&) {} |
| 3970 |
}; |
| 3971 |
static_assert(!__is_trivially_relocatable(NontrivialMoveCtor)); |
| 3972 |
static_assert(!__is_trivially_relocatable(NontrivialMoveCtor[])); |
| 3973 |
|
| 3974 |
struct [[clang::trivial_abi]] TrivialAbiNontrivialDtor { |
| 3975 |
~TrivialAbiNontrivialDtor() {} |
| 3976 |
}; |
| 3977 |
static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor)); |
| 3978 |
static_assert(__is_trivially_relocatable(TrivialAbiNontrivialDtor[])); |
| 3979 |
static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialDtor)); |
| 3980 |
static_assert(__is_trivially_relocatable(volatile TrivialAbiNontrivialDtor)); |
| 3981 |
|
| 3982 |
struct [[clang::trivial_abi]] TrivialAbiNontrivialCopyCtor { |
| 3983 |
TrivialAbiNontrivialCopyCtor(const TrivialAbiNontrivialCopyCtor&) {} |
| 3984 |
}; |
| 3985 |
static_assert(__is_trivially_relocatable(TrivialAbiNontrivialCopyCtor)); |
| 3986 |
static_assert(__is_trivially_relocatable(TrivialAbiNontrivialCopyCtor[])); |
| 3987 |
static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialCopyCtor)); |
| 3988 |
static_assert(__is_trivially_relocatable(volatile TrivialAbiNontrivialCopyCtor)); |
| 3989 |
|
| 3990 |
// A more complete set of tests for the behavior of trivial_abi can be found in |
| 3991 |
// clang/test/SemaCXX/attr-trivial-abi.cpp |
| 3992 |
struct [[clang::trivial_abi]] TrivialAbiNontrivialMoveCtor { |
| 3993 |
TrivialAbiNontrivialMoveCtor(TrivialAbiNontrivialMoveCtor&&) {} |
| 3994 |
}; |
| 3995 |
static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor)); |
| 3996 |
static_assert(__is_trivially_relocatable(TrivialAbiNontrivialMoveCtor[])); |
| 3997 |
static_assert(__is_trivially_relocatable(const TrivialAbiNontrivialMoveCtor)); |
| 3998 |
static_assert(__is_trivially_relocatable(volatile TrivialAbiNontrivialMoveCtor)); |
| 3999 |
|
| 4000 |
} // namespace is_trivially_relocatable |
| 4001 |
|
| 4002 |
namespace is_trivially_equality_comparable { |
| 4003 |
struct ForwardDeclared; // expected-note {{forward declaration of 'is_trivially_equality_comparable::ForwardDeclared'}} |
| 4004 |
static_assert(!__is_trivially_equality_comparable(ForwardDeclared)); // expected-error {{incomplete type 'ForwardDeclared' used in type trait expression}} |
| 4005 |
|
| 4006 |
static_assert(!__is_trivially_equality_comparable(void)); |
| 4007 |
static_assert(__is_trivially_equality_comparable(int)); |
| 4008 |
static_assert(!__is_trivially_equality_comparable(int[])); |
| 4009 |
static_assert(!__is_trivially_equality_comparable(int[3])); |
| 4010 |
static_assert(!__is_trivially_equality_comparable(float)); |
| 4011 |
static_assert(!__is_trivially_equality_comparable(double)); |
| 4012 |
static_assert(!__is_trivially_equality_comparable(long double)); |
| 4013 |
|
| 4014 |
struct NonTriviallyEqualityComparableNoComparator { |
| 4015 |
int i; |
| 4016 |
int j; |
| 4017 |
}; |
| 4018 |
static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNoComparator)); |
| 4019 |
|
| 4020 |
struct NonTriviallyEqualityComparableConvertibleToBuiltin { |
| 4021 |
int i; |
| 4022 |
operator unsigned() const; |
| 4023 |
}; |
| 4024 |
static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableConvertibleToBuiltin)); |
| 4025 |
|
| 4026 |
struct NonTriviallyEqualityComparableNonDefaultedComparator { |
| 4027 |
int i; |
| 4028 |
int j; |
| 4029 |
bool operator==(const NonTriviallyEqualityComparableNonDefaultedComparator&); |
| 4030 |
}; |
| 4031 |
static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableNonDefaultedComparator)); |
| 4032 |
|
| 4033 |
#if __cplusplus >= 202002L |
| 4034 |
|
| 4035 |
struct TriviallyEqualityComparable { |
| 4036 |
int i; |
| 4037 |
int j; |
| 4038 |
|
| 4039 |
void func(); |
| 4040 |
bool operator==(int) const { return false; } |
| 4041 |
|
| 4042 |
bool operator==(const TriviallyEqualityComparable&) const = default; |
| 4043 |
}; |
| 4044 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable)); |
| 4045 |
|
| 4046 |
struct TriviallyEqualityComparableContainsArray { |
| 4047 |
int a[4]; |
| 4048 |
|
| 4049 |
bool operator==(const TriviallyEqualityComparableContainsArray&) const = default; |
| 4050 |
}; |
| 4051 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsArray)); |
| 4052 |
|
| 4053 |
struct TriviallyEqualityComparableContainsMultiDimensionArray { |
| 4054 |
int a[4][4]; |
| 4055 |
|
| 4056 |
bool operator==(const TriviallyEqualityComparableContainsMultiDimensionArray&) const = default; |
| 4057 |
}; |
| 4058 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsMultiDimensionArray)); |
| 4059 |
|
| 4060 |
auto GetNonCapturingLambda() { return [](){ return 42; }; } |
| 4061 |
|
| 4062 |
struct TriviallyEqualityComparableContainsLambda { |
| 4063 |
[[no_unique_address]] decltype(GetNonCapturingLambda()) l; |
| 4064 |
int i; |
| 4065 |
|
| 4066 |
bool operator==(const TriviallyEqualityComparableContainsLambda&) const = default; |
| 4067 |
}; |
| 4068 |
static_assert(!__is_trivially_equality_comparable(decltype(GetNonCapturingLambda()))); // padding |
| 4069 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableContainsLambda)); |
| 4070 |
|
| 4071 |
struct TriviallyEqualityComparableNonTriviallyCopyable { |
| 4072 |
TriviallyEqualityComparableNonTriviallyCopyable(const TriviallyEqualityComparableNonTriviallyCopyable&); |
| 4073 |
~TriviallyEqualityComparableNonTriviallyCopyable(); |
| 4074 |
bool operator==(const TriviallyEqualityComparableNonTriviallyCopyable&) const = default; |
| 4075 |
int i; |
| 4076 |
}; |
| 4077 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableNonTriviallyCopyable)); |
| 4078 |
|
| 4079 |
struct NotTriviallyEqualityComparableHasPadding { |
| 4080 |
short i; |
| 4081 |
int j; |
| 4082 |
|
| 4083 |
bool operator==(const NotTriviallyEqualityComparableHasPadding&) const = default; |
| 4084 |
}; |
| 4085 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasPadding)); |
| 4086 |
|
| 4087 |
struct NotTriviallyEqualityComparableHasFloat { |
| 4088 |
float i; |
| 4089 |
int j; |
| 4090 |
|
| 4091 |
bool operator==(const NotTriviallyEqualityComparableHasFloat&) const = default; |
| 4092 |
}; |
| 4093 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasFloat)); |
| 4094 |
|
| 4095 |
struct NotTriviallyEqualityComparableHasTailPadding { |
| 4096 |
int i; |
| 4097 |
char j; |
| 4098 |
|
| 4099 |
bool operator==(const NotTriviallyEqualityComparableHasTailPadding&) const = default; |
| 4100 |
}; |
| 4101 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasTailPadding)); |
| 4102 |
|
| 4103 |
struct NotTriviallyEqualityComparableBase : NotTriviallyEqualityComparableHasTailPadding { |
| 4104 |
char j; |
| 4105 |
|
| 4106 |
bool operator==(const NotTriviallyEqualityComparableBase&) const = default; |
| 4107 |
}; |
| 4108 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBase)); |
| 4109 |
|
| 4110 |
class TriviallyEqualityComparablePaddedOutBase { |
| 4111 |
int i; |
| 4112 |
char c; |
| 4113 |
|
| 4114 |
public: |
| 4115 |
bool operator==(const TriviallyEqualityComparablePaddedOutBase&) const = default; |
| 4116 |
}; |
| 4117 |
static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparablePaddedOutBase)); |
| 4118 |
|
| 4119 |
struct TriviallyEqualityComparablePaddedOut : TriviallyEqualityComparablePaddedOutBase { |
| 4120 |
char j[3]; |
| 4121 |
|
| 4122 |
bool operator==(const TriviallyEqualityComparablePaddedOut&) const = default; |
| 4123 |
}; |
| 4124 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparablePaddedOut)); |
| 4125 |
|
| 4126 |
struct TriviallyEqualityComparable1 { |
| 4127 |
char i; |
| 4128 |
|
| 4129 |
bool operator==(const TriviallyEqualityComparable1&) const = default; |
| 4130 |
}; |
| 4131 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable1)); |
| 4132 |
|
| 4133 |
struct TriviallyEqualityComparable2 { |
| 4134 |
int i; |
| 4135 |
|
| 4136 |
bool operator==(const TriviallyEqualityComparable2&) const = default; |
| 4137 |
}; |
| 4138 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable2)); |
| 4139 |
|
| 4140 |
struct NotTriviallyEqualityComparableTriviallyEqualityComparableBases |
| 4141 |
: TriviallyEqualityComparable1, TriviallyEqualityComparable2 { |
| 4142 |
bool operator==(const NotTriviallyEqualityComparableTriviallyEqualityComparableBases&) const = default; |
| 4143 |
}; |
| 4144 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableTriviallyEqualityComparableBases)); |
| 4145 |
|
| 4146 |
struct NotTriviallyEqualityComparableBitfield { |
| 4147 |
int i : 1; |
| 4148 |
|
| 4149 |
bool operator==(const NotTriviallyEqualityComparableBitfield&) const = default; |
| 4150 |
}; |
| 4151 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBitfield)); |
| 4152 |
|
| 4153 |
// TODO: This is trivially equality comparable |
| 4154 |
struct NotTriviallyEqualityComparableBitfieldFilled { |
| 4155 |
char i : __CHAR_BIT__; |
| 4156 |
|
| 4157 |
bool operator==(const NotTriviallyEqualityComparableBitfieldFilled&) const = default; |
| 4158 |
}; |
| 4159 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBitfield)); |
| 4160 |
|
| 4161 |
union U { |
| 4162 |
int i; |
| 4163 |
|
| 4164 |
bool operator==(const U&) const = default; |
| 4165 |
}; |
| 4166 |
|
| 4167 |
struct NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion { |
| 4168 |
U u; |
| 4169 |
|
| 4170 |
bool operator==(const NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion&) const = default; |
| 4171 |
}; |
| 4172 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion)); |
| 4173 |
|
| 4174 |
struct NotTriviallyEqualityComparableExplicitlyDeleted { |
| 4175 |
int i; |
| 4176 |
|
| 4177 |
bool operator==(const NotTriviallyEqualityComparableExplicitlyDeleted&) const = delete; |
| 4178 |
}; |
| 4179 |
|
| 4180 |
struct NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct { |
| 4181 |
NotTriviallyEqualityComparableExplicitlyDeleted u; |
| 4182 |
|
| 4183 |
bool operator==(const NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct&) const = default; |
| 4184 |
}; |
| 4185 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct)); |
| 4186 |
|
| 4187 |
struct NotTriviallyEqualityComparableHasReferenceMember { |
| 4188 |
int& i; |
| 4189 |
|
| 4190 |
bool operator==(const NotTriviallyEqualityComparableHasReferenceMember&) const = default; |
| 4191 |
}; |
| 4192 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasReferenceMember)); |
| 4193 |
|
| 4194 |
struct NotTriviallyEqualityComparableNonTriviallyComparableBaseBase { |
| 4195 |
int i; |
| 4196 |
|
| 4197 |
bool operator==(const NotTriviallyEqualityComparableNonTriviallyComparableBaseBase&) const { |
| 4198 |
return true; |
| 4199 |
} |
| 4200 |
}; |
| 4201 |
|
| 4202 |
struct NotTriviallyEqualityComparableNonTriviallyComparableBase : NotTriviallyEqualityComparableNonTriviallyComparableBaseBase { |
| 4203 |
int i; |
| 4204 |
|
| 4205 |
bool operator==(const NotTriviallyEqualityComparableNonTriviallyComparableBase&) const = default; |
| 4206 |
}; |
| 4207 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyComparableBase)); |
| 4208 |
|
| 4209 |
enum E { |
| 4210 |
a, |
| 4211 |
b |
| 4212 |
}; |
| 4213 |
bool operator==(E, E) { return false; } |
| 4214 |
static_assert(!__is_trivially_equality_comparable(E)); |
| 4215 |
|
| 4216 |
struct NotTriviallyEqualityComparableHasEnum { |
| 4217 |
E e; |
| 4218 |
bool operator==(const NotTriviallyEqualityComparableHasEnum&) const = default; |
| 4219 |
}; |
| 4220 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasEnum)); |
| 4221 |
|
| 4222 |
struct NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs { |
| 4223 |
E e[1]; |
| 4224 |
|
| 4225 |
bool operator==(const NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs&) const = default; |
| 4226 |
}; |
| 4227 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs)); |
| 4228 |
|
| 4229 |
struct NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2 { |
| 4230 |
E e[1][1]; |
| 4231 |
|
| 4232 |
bool operator==(const NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2&) const = default; |
| 4233 |
}; |
| 4234 |
|
| 4235 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableNonTriviallyEqualityComparableArrs2)); |
| 4236 |
|
| 4237 |
struct NotTriviallyEqualityComparablePrivateComparison { |
| 4238 |
int i; |
| 4239 |
|
| 4240 |
private: |
| 4241 |
bool operator==(const NotTriviallyEqualityComparablePrivateComparison&) const = default; |
| 4242 |
}; |
| 4243 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparablePrivateComparison)); |
| 4244 |
|
| 4245 |
template<typename T, bool result = __is_trivially_equality_comparable(T)> |
| 4246 |
static constexpr bool is_trivially_equality_comparable_sfinae() { return result; } |
| 4247 |
|
| 4248 |
// Make sure we don't emit "'operator==' is a private member" in SFINAE context. |
| 4249 |
static_assert(!is_trivially_equality_comparable_sfinae<NotTriviallyEqualityComparablePrivateComparison>()); |
| 4250 |
|
| 4251 |
template<bool B> |
| 4252 |
struct MaybeTriviallyEqualityComparable { |
| 4253 |
int i; |
| 4254 |
bool operator==(const MaybeTriviallyEqualityComparable&) const requires B = default; |
| 4255 |
bool operator==(const MaybeTriviallyEqualityComparable& rhs) const { return (i % 3) == (rhs.i % 3); } |
| 4256 |
}; |
| 4257 |
static_assert(__is_trivially_equality_comparable(MaybeTriviallyEqualityComparable<true>)); |
| 4258 |
static_assert(!__is_trivially_equality_comparable(MaybeTriviallyEqualityComparable<false>)); |
| 4259 |
|
| 4260 |
struct NotTriviallyEqualityComparableMoreConstrainedExternalOp { |
| 4261 |
int i; |
| 4262 |
bool operator==(const NotTriviallyEqualityComparableMoreConstrainedExternalOp&) const = default; |
| 4263 |
}; |
| 4264 |
|
| 4265 |
bool operator==(const NotTriviallyEqualityComparableMoreConstrainedExternalOp&, |
| 4266 |
const NotTriviallyEqualityComparableMoreConstrainedExternalOp&) __attribute__((enable_if(true, ""))) {} |
| 4267 |
|
| 4268 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableMoreConstrainedExternalOp)); |
| 4269 |
|
| 4270 |
struct TriviallyEqualityComparableExternalDefaultedOp { |
| 4271 |
int i; |
| 4272 |
friend bool operator==(TriviallyEqualityComparableExternalDefaultedOp, TriviallyEqualityComparableExternalDefaultedOp); |
| 4273 |
}; |
| 4274 |
bool operator==(TriviallyEqualityComparableExternalDefaultedOp, TriviallyEqualityComparableExternalDefaultedOp) = default; |
| 4275 |
|
| 4276 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableExternalDefaultedOp)); |
| 4277 |
|
| 4278 |
struct EqualityComparableBase { |
| 4279 |
bool operator==(const EqualityComparableBase&) const = default; |
| 4280 |
}; |
| 4281 |
|
| 4282 |
struct ComparingBaseOnly : EqualityComparableBase { |
| 4283 |
int j_ = 0; |
| 4284 |
}; |
| 4285 |
static_assert(!__is_trivially_equality_comparable(ComparingBaseOnly)); |
| 4286 |
|
| 4287 |
template <class> |
| 4288 |
class Template {}; |
| 4289 |
|
| 4290 |
// Make sure we don't crash when instantiating a type |
| 4291 |
static_assert(!__is_trivially_equality_comparable(Template<Template<int>>)); |
| 4292 |
|
| 4293 |
|
| 4294 |
struct S operator==(S, S); |
| 4295 |
|
| 4296 |
template <class> struct basic_string_view {}; |
| 4297 |
|
| 4298 |
struct basic_string { |
| 4299 |
operator basic_string_view<int>() const; |
| 4300 |
}; |
| 4301 |
|
| 4302 |
template <class T> |
| 4303 |
const bool is_trivially_equality_comparable = __is_trivially_equality_comparable(T); |
| 4304 |
|
| 4305 |
template <int = is_trivially_equality_comparable<basic_string> > |
| 4306 |
void find(); |
| 4307 |
|
| 4308 |
void func() { find(); } |
| 4309 |
|
| 4310 |
|
| 4311 |
namespace hidden_friend { |
| 4312 |
|
| 4313 |
struct TriviallyEqualityComparable { |
| 4314 |
int i; |
| 4315 |
int j; |
| 4316 |
|
| 4317 |
void func(); |
| 4318 |
bool operator==(int) const { return false; } |
| 4319 |
|
| 4320 |
friend bool operator==(const TriviallyEqualityComparable&, const TriviallyEqualityComparable&) = default; |
| 4321 |
}; |
| 4322 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable)); |
| 4323 |
|
| 4324 |
struct TriviallyEqualityComparableNonTriviallyCopyable { |
| 4325 |
TriviallyEqualityComparableNonTriviallyCopyable(const TriviallyEqualityComparableNonTriviallyCopyable&); |
| 4326 |
~TriviallyEqualityComparableNonTriviallyCopyable(); |
| 4327 |
friend bool operator==(const TriviallyEqualityComparableNonTriviallyCopyable&, const TriviallyEqualityComparableNonTriviallyCopyable&) = default; |
| 4328 |
int i; |
| 4329 |
}; |
| 4330 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableNonTriviallyCopyable)); |
| 4331 |
|
| 4332 |
struct NotTriviallyEqualityComparableHasPadding { |
| 4333 |
short i; |
| 4334 |
int j; |
| 4335 |
|
| 4336 |
friend bool operator==(const NotTriviallyEqualityComparableHasPadding&, const NotTriviallyEqualityComparableHasPadding&) = default; |
| 4337 |
}; |
| 4338 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasPadding)); |
| 4339 |
|
| 4340 |
struct NotTriviallyEqualityComparableHasFloat { |
| 4341 |
float i; |
| 4342 |
int j; |
| 4343 |
|
| 4344 |
friend bool operator==(const NotTriviallyEqualityComparableHasFloat&, const NotTriviallyEqualityComparableHasFloat&) = default; |
| 4345 |
}; |
| 4346 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasFloat)); |
| 4347 |
|
| 4348 |
struct NotTriviallyEqualityComparableHasTailPadding { |
| 4349 |
int i; |
| 4350 |
char j; |
| 4351 |
|
| 4352 |
friend bool operator==(const NotTriviallyEqualityComparableHasTailPadding&, const NotTriviallyEqualityComparableHasTailPadding&) = default; |
| 4353 |
}; |
| 4354 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasTailPadding)); |
| 4355 |
|
| 4356 |
struct NotTriviallyEqualityComparableBase : NotTriviallyEqualityComparableHasTailPadding { |
| 4357 |
char j; |
| 4358 |
|
| 4359 |
friend bool operator==(const NotTriviallyEqualityComparableBase&, const NotTriviallyEqualityComparableBase&) = default; |
| 4360 |
}; |
| 4361 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBase)); |
| 4362 |
|
| 4363 |
class TriviallyEqualityComparablePaddedOutBase { |
| 4364 |
int i; |
| 4365 |
char c; |
| 4366 |
|
| 4367 |
public: |
| 4368 |
friend bool operator==(const TriviallyEqualityComparablePaddedOutBase&, const TriviallyEqualityComparablePaddedOutBase&) = default; |
| 4369 |
}; |
| 4370 |
static_assert(!__is_trivially_equality_comparable(TriviallyEqualityComparablePaddedOutBase)); |
| 4371 |
|
| 4372 |
struct TriviallyEqualityComparablePaddedOut : TriviallyEqualityComparablePaddedOutBase { |
| 4373 |
char j[3]; |
| 4374 |
|
| 4375 |
friend bool operator==(const TriviallyEqualityComparablePaddedOut&, const TriviallyEqualityComparablePaddedOut&) = default; |
| 4376 |
}; |
| 4377 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparablePaddedOut)); |
| 4378 |
|
| 4379 |
struct TriviallyEqualityComparable1 { |
| 4380 |
char i; |
| 4381 |
|
| 4382 |
friend bool operator==(const TriviallyEqualityComparable1&, const TriviallyEqualityComparable1&) = default; |
| 4383 |
}; |
| 4384 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable1)); |
| 4385 |
|
| 4386 |
struct TriviallyEqualityComparable2 { |
| 4387 |
int i; |
| 4388 |
|
| 4389 |
friend bool operator==(const TriviallyEqualityComparable2&, const TriviallyEqualityComparable2&) = default; |
| 4390 |
}; |
| 4391 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparable2)); |
| 4392 |
|
| 4393 |
struct NotTriviallyEqualityComparableTriviallyEqualityComparableBases |
| 4394 |
: TriviallyEqualityComparable1, TriviallyEqualityComparable2 { |
| 4395 |
friend bool operator==(const NotTriviallyEqualityComparableTriviallyEqualityComparableBases&, const NotTriviallyEqualityComparableTriviallyEqualityComparableBases&) = default; |
| 4396 |
}; |
| 4397 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableTriviallyEqualityComparableBases)); |
| 4398 |
|
| 4399 |
struct NotTriviallyEqualityComparableBitfield { |
| 4400 |
int i : 1; |
| 4401 |
|
| 4402 |
friend bool operator==(const NotTriviallyEqualityComparableBitfield&, const NotTriviallyEqualityComparableBitfield&) = default; |
| 4403 |
}; |
| 4404 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBitfield)); |
| 4405 |
|
| 4406 |
// TODO: This is trivially equality comparable |
| 4407 |
struct NotTriviallyEqualityComparableBitfieldFilled { |
| 4408 |
char i : __CHAR_BIT__; |
| 4409 |
|
| 4410 |
friend bool operator==(const NotTriviallyEqualityComparableBitfieldFilled&, const NotTriviallyEqualityComparableBitfieldFilled&) = default; |
| 4411 |
}; |
| 4412 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableBitfield)); |
| 4413 |
|
| 4414 |
union U { |
| 4415 |
int i; |
| 4416 |
|
| 4417 |
friend bool operator==(const U&, const U&) = default; |
| 4418 |
}; |
| 4419 |
|
| 4420 |
struct NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion { |
| 4421 |
U u; |
| 4422 |
|
| 4423 |
friend bool operator==(const NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion&, const NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion&) = default; |
| 4424 |
}; |
| 4425 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableImplicitlyDeletedOperatorByUnion)); |
| 4426 |
|
| 4427 |
struct NotTriviallyEqualityComparableExplicitlyDeleted { |
| 4428 |
int i; |
| 4429 |
|
| 4430 |
friend bool operator==(const NotTriviallyEqualityComparableExplicitlyDeleted&, const NotTriviallyEqualityComparableExplicitlyDeleted&) = delete; |
| 4431 |
}; |
| 4432 |
|
| 4433 |
struct NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct { |
| 4434 |
NotTriviallyEqualityComparableExplicitlyDeleted u; |
| 4435 |
|
| 4436 |
friend bool operator==(const NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct&, const NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct&) = default; |
| 4437 |
}; |
| 4438 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableImplicitlyDeletedOperatorByStruct)); |
| 4439 |
|
| 4440 |
struct NotTriviallyEqualityComparableHasReferenceMember { |
| 4441 |
int& i; |
| 4442 |
|
| 4443 |
friend bool operator==(const NotTriviallyEqualityComparableHasReferenceMember&, const NotTriviallyEqualityComparableHasReferenceMember&) = default; |
| 4444 |
}; |
| 4445 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasReferenceMember)); |
| 4446 |
|
| 4447 |
enum E { |
| 4448 |
a, |
| 4449 |
b |
| 4450 |
}; |
| 4451 |
bool operator==(E, E) { return false; } |
| 4452 |
static_assert(!__is_trivially_equality_comparable(E)); |
| 4453 |
|
| 4454 |
struct NotTriviallyEqualityComparableHasEnum { |
| 4455 |
E e; |
| 4456 |
friend bool operator==(const NotTriviallyEqualityComparableHasEnum&, const NotTriviallyEqualityComparableHasEnum&) = default; |
| 4457 |
}; |
| 4458 |
static_assert(!__is_trivially_equality_comparable(NotTriviallyEqualityComparableHasEnum)); |
| 4459 |
|
| 4460 |
struct NonTriviallyEqualityComparableValueComparisonNonTriviallyCopyable { |
| 4461 |
int i; |
| 4462 |
NonTriviallyEqualityComparableValueComparisonNonTriviallyCopyable(const NonTriviallyEqualityComparableValueComparisonNonTriviallyCopyable&); |
| 4463 |
|
| 4464 |
friend bool operator==(NonTriviallyEqualityComparableValueComparisonNonTriviallyCopyable, NonTriviallyEqualityComparableValueComparisonNonTriviallyCopyable) = default; |
| 4465 |
}; |
| 4466 |
static_assert(!__is_trivially_equality_comparable(NonTriviallyEqualityComparableValueComparisonNonTriviallyCopyable)); |
| 4467 |
|
| 4468 |
struct TriviallyEqualityComparableRefComparisonNonTriviallyCopyable { |
| 4469 |
int i; |
| 4470 |
TriviallyEqualityComparableRefComparisonNonTriviallyCopyable(const TriviallyEqualityComparableRefComparisonNonTriviallyCopyable&); |
| 4471 |
|
| 4472 |
friend bool operator==(const TriviallyEqualityComparableRefComparisonNonTriviallyCopyable&, const TriviallyEqualityComparableRefComparisonNonTriviallyCopyable&) = default; |
| 4473 |
}; |
| 4474 |
static_assert(__is_trivially_equality_comparable(TriviallyEqualityComparableRefComparisonNonTriviallyCopyable)); |
| 4475 |
} |
| 4476 |
|
| 4477 |
#endif // __cplusplus >= 202002L |
| 4478 |
}; |
| 4479 |
|
| 4480 |
namespace can_pass_in_regs { |
| 4481 |
|
| 4482 |
struct A { }; |
| 4483 |
|
| 4484 |
struct B { |
| 4485 |
~B(); |
| 4486 |
}; |
| 4487 |
|
| 4488 |
struct C; // expected-note {{forward declaration}} |
| 4489 |
|
| 4490 |
union D { |
| 4491 |
int x; |
| 4492 |
}; |
| 4493 |
|
| 4494 |
static_assert(__can_pass_in_regs(A)); |
| 4495 |
static_assert(__can_pass_in_regs(A)); |
| 4496 |
static_assert(!__can_pass_in_regs(B)); |
| 4497 |
static_assert(__can_pass_in_regs(D)); |
| 4498 |
|
| 4499 |
void test_errors() { |
| 4500 |
(void)__can_pass_in_regs(const A); // expected-error {{not an unqualified class type}} |
| 4501 |
(void)__can_pass_in_regs(A&); // expected-error {{not an unqualified class type}} |
| 4502 |
(void)__can_pass_in_regs(A&&); // expected-error {{not an unqualified class type}} |
| 4503 |
(void)__can_pass_in_regs(const A&); // expected-error {{not an unqualified class type}} |
| 4504 |
(void)__can_pass_in_regs(C); // expected-error {{incomplete type}} |
| 4505 |
(void)__can_pass_in_regs(int); // expected-error {{not an unqualified class type}} |
| 4506 |
(void)__can_pass_in_regs(int&); // expected-error {{not an unqualified class type}} |
| 4507 |
} |
| 4508 |
} |
| 4509 |
|
| 4510 |
struct S {}; |
| 4511 |
template <class T> using remove_const_t = __remove_const(T); |
| 4512 |
|
| 4513 |
void check_remove_const() { |
| 4514 |
static_assert(__is_same(remove_const_t<void>, void)); |
| 4515 |
static_assert(__is_same(remove_const_t<const void>, void)); |
| 4516 |
static_assert(__is_same(remove_const_t<int>, int)); |
| 4517 |
static_assert(__is_same(remove_const_t<const int>, int)); |
| 4518 |
static_assert(__is_same(remove_const_t<volatile int>, volatile int)); |
| 4519 |
static_assert(__is_same(remove_const_t<const volatile int>, volatile int)); |
| 4520 |
static_assert(__is_same(remove_const_t<int *>, int *)); |
| 4521 |
static_assert(__is_same(remove_const_t<int *const>, int *)); |
| 4522 |
static_assert(__is_same(remove_const_t<int const *const>, int const *)); |
| 4523 |
static_assert(__is_same(remove_const_t<int const *const __restrict>, int const *__restrict)); |
| 4524 |
static_assert(__is_same(remove_const_t<int &>, int &)); |
| 4525 |
static_assert(__is_same(remove_const_t<int const &>, int const &)); |
| 4526 |
static_assert(__is_same(remove_const_t<int &&>, int &&)); |
| 4527 |
static_assert(__is_same(remove_const_t<int const &&>, int const &&)); |
| 4528 |
static_assert(__is_same(remove_const_t<int()>, int())); |
| 4529 |
static_assert(__is_same(remove_const_t<int (*const)()>, int (*)())); |
| 4530 |
static_assert(__is_same(remove_const_t<int (&)()>, int (&)())); |
| 4531 |
|
| 4532 |
static_assert(__is_same(remove_const_t<S>, S)); |
| 4533 |
static_assert(__is_same(remove_const_t<const S>, S)); |
| 4534 |
static_assert(__is_same(remove_const_t<volatile S>, volatile S)); |
| 4535 |
static_assert(__is_same(remove_const_t<S *__restrict>, S *__restrict)); |
| 4536 |
static_assert(__is_same(remove_const_t<const volatile S>, volatile S)); |
| 4537 |
static_assert(__is_same(remove_const_t<S *const volatile __restrict>, S *volatile __restrict)); |
| 4538 |
static_assert(__is_same(remove_const_t<int S::*const>, int S::*)); |
| 4539 |
static_assert(__is_same(remove_const_t<int (S::*const)()>, int(S::*)())); |
| 4540 |
} |
| 4541 |
|
| 4542 |
template <class T> using remove_restrict_t = __remove_restrict(T); |
| 4543 |
|
| 4544 |
void check_remove_restrict() { |
| 4545 |
static_assert(__is_same(remove_restrict_t<void>, void)); |
| 4546 |
static_assert(__is_same(remove_restrict_t<int>, int)); |
| 4547 |
static_assert(__is_same(remove_restrict_t<const int>, const int)); |
| 4548 |
static_assert(__is_same(remove_restrict_t<volatile int>, volatile int)); |
| 4549 |
static_assert(__is_same(remove_restrict_t<int *__restrict>, int *)); |
| 4550 |
static_assert(__is_same(remove_restrict_t<int *const volatile __restrict>, int *const volatile)); |
| 4551 |
static_assert(__is_same(remove_restrict_t<int *>, int *)); |
| 4552 |
static_assert(__is_same(remove_restrict_t<int *__restrict>, int *)); |
| 4553 |
static_assert(__is_same(remove_restrict_t<int &>, int &)); |
| 4554 |
static_assert(__is_same(remove_restrict_t<int &__restrict>, int &)); |
| 4555 |
static_assert(__is_same(remove_restrict_t<int &&>, int &&)); |
| 4556 |
static_assert(__is_same(remove_restrict_t<int &&__restrict>, int &&)); |
| 4557 |
static_assert(__is_same(remove_restrict_t<int()>, int())); |
| 4558 |
static_assert(__is_same(remove_restrict_t<int (*const volatile)()>, int (*const volatile)())); |
| 4559 |
static_assert(__is_same(remove_restrict_t<int (&)()>, int (&)())); |
| 4560 |
|
| 4561 |
static_assert(__is_same(remove_restrict_t<S>, S)); |
| 4562 |
static_assert(__is_same(remove_restrict_t<const S>, const S)); |
| 4563 |
static_assert(__is_same(remove_restrict_t<volatile S>, volatile S)); |
| 4564 |
static_assert(__is_same(remove_restrict_t<S *__restrict>, S *)); |
| 4565 |
static_assert(__is_same(remove_restrict_t<S *const volatile __restrict>, S *const volatile)); |
| 4566 |
static_assert(__is_same(remove_restrict_t<int S::*__restrict>, int S::*)); |
| 4567 |
static_assert(__is_same(remove_restrict_t<int (S::*const volatile)()>, int(S::*const volatile)())); |
| 4568 |
} |
| 4569 |
|
| 4570 |
template <class T> using remove_volatile_t = __remove_volatile(T); |
| 4571 |
|
| 4572 |
void check_remove_volatile() { |
| 4573 |
static_assert(__is_same(remove_volatile_t<void>, void)); |
| 4574 |
static_assert(__is_same(remove_volatile_t<volatile void>, void)); |
| 4575 |
static_assert(__is_same(remove_volatile_t<int>, int)); |
| 4576 |
static_assert(__is_same(remove_volatile_t<const int>, const int)); |
| 4577 |
static_assert(__is_same(remove_volatile_t<volatile int>, int)); |
| 4578 |
static_assert(__is_same(remove_volatile_t<int *__restrict>, int *__restrict)); |
| 4579 |
static_assert(__is_same(remove_volatile_t<const volatile int>, const int)); |
| 4580 |
static_assert(__is_same(remove_volatile_t<int *const volatile __restrict>, int *const __restrict)); |
| 4581 |
static_assert(__is_same(remove_volatile_t<int *>, int *)); |
| 4582 |
static_assert(__is_same(remove_volatile_t<int *volatile>, int *)); |
| 4583 |
static_assert(__is_same(remove_volatile_t<int volatile *volatile>, int volatile *)); |
| 4584 |
static_assert(__is_same(remove_volatile_t<int &>, int &)); |
| 4585 |
static_assert(__is_same(remove_volatile_t<int volatile &>, int volatile &)); |
| 4586 |
static_assert(__is_same(remove_volatile_t<int &&>, int &&)); |
| 4587 |
static_assert(__is_same(remove_volatile_t<int volatile &&>, int volatile &&)); |
| 4588 |
static_assert(__is_same(remove_volatile_t<int()>, int())); |
| 4589 |
static_assert(__is_same(remove_volatile_t<int (*volatile)()>, int (*)())); |
| 4590 |
static_assert(__is_same(remove_volatile_t<int (&)()>, int (&)())); |
| 4591 |
|
| 4592 |
static_assert(__is_same(remove_volatile_t<S>, S)); |
| 4593 |
static_assert(__is_same(remove_volatile_t<const S>, const S)); |
| 4594 |
static_assert(__is_same(remove_volatile_t<volatile S>, S)); |
| 4595 |
static_assert(__is_same(remove_volatile_t<const volatile S>, const S)); |
| 4596 |
static_assert(__is_same(remove_volatile_t<int S::*volatile>, int S::*)); |
| 4597 |
static_assert(__is_same(remove_volatile_t<int (S::*volatile)()>, int(S::*)())); |
| 4598 |
} |
| 4599 |
|
| 4600 |
template <class T> using remove_cv_t = __remove_cv(T); |
| 4601 |
|
| 4602 |
void check_remove_cv() { |
| 4603 |
static_assert(__is_same(remove_cv_t<void>, void)); |
| 4604 |
static_assert(__is_same(remove_cv_t<const volatile void>, void)); |
| 4605 |
static_assert(__is_same(remove_cv_t<int>, int)); |
| 4606 |
static_assert(__is_same(remove_cv_t<const int>, int)); |
| 4607 |
static_assert(__is_same(remove_cv_t<volatile int>, int)); |
| 4608 |
static_assert(__is_same(remove_cv_t<const volatile int>, int)); |
| 4609 |
static_assert(__is_same(remove_cv_t<int *>, int *)); |
| 4610 |
static_assert(__is_same(remove_cv_t<int *const volatile>, int *)); |
| 4611 |
static_assert(__is_same(remove_cv_t<int const *const volatile>, int const *)); |
| 4612 |
static_assert(__is_same(remove_cv_t<int const *const volatile __restrict>, int const *__restrict)); |
| 4613 |
static_assert(__is_same(remove_cv_t<int const *const volatile _Nonnull>, int const *_Nonnull)); |
| 4614 |
static_assert(__is_same(remove_cv_t<int &>, int &)); |
| 4615 |
static_assert(__is_same(remove_cv_t<int const volatile &>, int const volatile &)); |
| 4616 |
static_assert(__is_same(remove_cv_t<int &&>, int &&)); |
| 4617 |
static_assert(__is_same(remove_cv_t<int const volatile &&>, int const volatile &&)); |
| 4618 |
static_assert(__is_same(remove_cv_t<int()>, int())); |
| 4619 |
static_assert(__is_same(remove_cv_t<int (*const volatile)()>, int (*)())); |
| 4620 |
static_assert(__is_same(remove_cv_t<int (&)()>, int (&)())); |
| 4621 |
|
| 4622 |
static_assert(__is_same(remove_cv_t<S>, S)); |
| 4623 |
static_assert(__is_same(remove_cv_t<const S>, S)); |
| 4624 |
static_assert(__is_same(remove_cv_t<volatile S>, S)); |
| 4625 |
static_assert(__is_same(remove_cv_t<const volatile S>, S)); |
| 4626 |
static_assert(__is_same(remove_cv_t<int S::*const volatile>, int S::*)); |
| 4627 |
static_assert(__is_same(remove_cv_t<int (S::*const volatile)()>, int(S::*)())); |
| 4628 |
} |
| 4629 |
|
| 4630 |
template <class T> using add_pointer_t = __add_pointer(T); |
| 4631 |
|
| 4632 |
void add_pointer() { |
| 4633 |
static_assert(__is_same(add_pointer_t<void>, void *)); |
| 4634 |
static_assert(__is_same(add_pointer_t<const void>, const void *)); |
| 4635 |
static_assert(__is_same(add_pointer_t<volatile void>, volatile void *)); |
| 4636 |
static_assert(__is_same(add_pointer_t<const volatile void>, const volatile void *)); |
| 4637 |
static_assert(__is_same(add_pointer_t<int>, int *)); |
| 4638 |
static_assert(__is_same(add_pointer_t<const int>, const int *)); |
| 4639 |
static_assert(__is_same(add_pointer_t<volatile int>, volatile int *)); |
| 4640 |
static_assert(__is_same(add_pointer_t<const volatile int>, const volatile int *)); |
| 4641 |
static_assert(__is_same(add_pointer_t<int *>, int **)); |
| 4642 |
static_assert(__is_same(add_pointer_t<int &>, int *)); |
| 4643 |
static_assert(__is_same(add_pointer_t<int &&>, int *)); |
| 4644 |
static_assert(__is_same(add_pointer_t<int()>, int (*)())); |
| 4645 |
static_assert(__is_same(add_pointer_t<int (*)()>, int (**)())); |
| 4646 |
static_assert(__is_same(add_pointer_t<int (&)()>, int (*)())); |
| 4647 |
|
| 4648 |
static_assert(__is_same(add_pointer_t<S>, S *)); |
| 4649 |
static_assert(__is_same(add_pointer_t<const S>, const S *)); |
| 4650 |
static_assert(__is_same(add_pointer_t<volatile S>, volatile S *)); |
| 4651 |
static_assert(__is_same(add_pointer_t<const volatile S>, const volatile S *)); |
| 4652 |
static_assert(__is_same(add_pointer_t<int S::*>, int S::**)); |
| 4653 |
static_assert(__is_same(add_pointer_t<int (S::*)()>, int(S::**)())); |
| 4654 |
|
| 4655 |
static_assert(__is_same(add_pointer_t<int __attribute__((address_space(1)))>, int __attribute__((address_space(1))) *)); |
| 4656 |
static_assert(__is_same(add_pointer_t<S __attribute__((address_space(2)))>, S __attribute__((address_space(2))) *)); |
| 4657 |
} |
| 4658 |
|
| 4659 |
template <class T> using remove_pointer_t = __remove_pointer(T); |
| 4660 |
|
| 4661 |
void remove_pointer() { |
| 4662 |
static_assert(__is_same(remove_pointer_t<void>, void)); |
| 4663 |
static_assert(__is_same(remove_pointer_t<const void>, const void)); |
| 4664 |
static_assert(__is_same(remove_pointer_t<volatile void>, volatile void)); |
| 4665 |
static_assert(__is_same(remove_pointer_t<const volatile void>, const volatile void)); |
| 4666 |
static_assert(__is_same(remove_pointer_t<int>, int)); |
| 4667 |
static_assert(__is_same(remove_pointer_t<const int>, const int)); |
| 4668 |
static_assert(__is_same(remove_pointer_t<volatile int>, volatile int)); |
| 4669 |
static_assert(__is_same(remove_pointer_t<const volatile int>, const volatile int)); |
| 4670 |
static_assert(__is_same(remove_pointer_t<int *>, int)); |
| 4671 |
static_assert(__is_same(remove_pointer_t<const int *>, const int)); |
| 4672 |
static_assert(__is_same(remove_pointer_t<volatile int *>, volatile int)); |
| 4673 |
static_assert(__is_same(remove_pointer_t<const volatile int *>, const volatile int)); |
| 4674 |
static_assert(__is_same(remove_pointer_t<int *const>, int)); |
| 4675 |
static_assert(__is_same(remove_pointer_t<int *volatile>, int)); |
| 4676 |
static_assert(__is_same(remove_pointer_t<int *const volatile>, int)); |
| 4677 |
static_assert(__is_same(remove_pointer_t<int &>, int &)); |
| 4678 |
static_assert(__is_same(remove_pointer_t<int &&>, int &&)); |
| 4679 |
static_assert(__is_same(remove_pointer_t<int()>, int())); |
| 4680 |
static_assert(__is_same(remove_pointer_t<int (*)()>, int())); |
| 4681 |
static_assert(__is_same(remove_pointer_t<int (&)()>, int (&)())); |
| 4682 |
|
| 4683 |
static_assert(__is_same(remove_pointer_t<S>, S)); |
| 4684 |
static_assert(__is_same(remove_pointer_t<const S>, const S)); |
| 4685 |
static_assert(__is_same(remove_pointer_t<volatile S>, volatile S)); |
| 4686 |
static_assert(__is_same(remove_pointer_t<const volatile S>, const volatile S)); |
| 4687 |
static_assert(__is_same(remove_pointer_t<int S::*>, int S::*)); |
| 4688 |
static_assert(__is_same(remove_pointer_t<int (S::*)()>, int(S::*)())); |
| 4689 |
|
| 4690 |
static_assert(__is_same(remove_pointer_t<int __attribute__((address_space(1))) *>, int __attribute__((address_space(1))))); |
| 4691 |
static_assert(__is_same(remove_pointer_t<S __attribute__((address_space(2))) *>, S __attribute__((address_space(2))))); |
| 4692 |
|
| 4693 |
static_assert(__is_same(remove_pointer_t<int (^)(char)>, int (^)(char))); |
| 4694 |
} |
| 4695 |
|
| 4696 |
template <class T> using add_lvalue_reference_t = __add_lvalue_reference(T); |
| 4697 |
|
| 4698 |
void add_lvalue_reference() { |
| 4699 |
static_assert(__is_same(add_lvalue_reference_t<void>, void)); |
| 4700 |
static_assert(__is_same(add_lvalue_reference_t<const void>, const void)); |
| 4701 |
static_assert(__is_same(add_lvalue_reference_t<volatile void>, volatile void)); |
| 4702 |
static_assert(__is_same(add_lvalue_reference_t<const volatile void>, const volatile void)); |
| 4703 |
static_assert(__is_same(add_lvalue_reference_t<int>, int &)); |
| 4704 |
static_assert(__is_same(add_lvalue_reference_t<const int>, const int &)); |
| 4705 |
static_assert(__is_same(add_lvalue_reference_t<volatile int>, volatile int &)); |
| 4706 |
static_assert(__is_same(add_lvalue_reference_t<const volatile int>, const volatile int &)); |
| 4707 |
static_assert(__is_same(add_lvalue_reference_t<int *>, int *&)); |
| 4708 |
static_assert(__is_same(add_lvalue_reference_t<int &>, int &)); |
| 4709 |
static_assert(__is_same(add_lvalue_reference_t<int &&>, int &)); // reference collapsing |
| 4710 |
static_assert(__is_same(add_lvalue_reference_t<int()>, int (&)())); |
| 4711 |
static_assert(__is_same(add_lvalue_reference_t<int (*)()>, int (*&)())); |
| 4712 |
static_assert(__is_same(add_lvalue_reference_t<int (&)()>, int (&)())); |
| 4713 |
|
| 4714 |
static_assert(__is_same(add_lvalue_reference_t<S>, S &)); |
| 4715 |
static_assert(__is_same(add_lvalue_reference_t<const S>, const S &)); |
| 4716 |
static_assert(__is_same(add_lvalue_reference_t<volatile S>, volatile S &)); |
| 4717 |
static_assert(__is_same(add_lvalue_reference_t<const volatile S>, const volatile S &)); |
| 4718 |
static_assert(__is_same(add_lvalue_reference_t<int S::*>, int S::*&)); |
| 4719 |
static_assert(__is_same(add_lvalue_reference_t<int (S::*)()>, int(S::*&)())); |
| 4720 |
} |
| 4721 |
|
| 4722 |
template <class T> using add_rvalue_reference_t = __add_rvalue_reference(T); |
| 4723 |
|
| 4724 |
void add_rvalue_reference() { |
| 4725 |
static_assert(__is_same(add_rvalue_reference_t<void>, void)); |
| 4726 |
static_assert(__is_same(add_rvalue_reference_t<const void>, const void)); |
| 4727 |
static_assert(__is_same(add_rvalue_reference_t<volatile void>, volatile void)); |
| 4728 |
static_assert(__is_same(add_rvalue_reference_t<const volatile void>, const volatile void)); |
| 4729 |
static_assert(__is_same(add_rvalue_reference_t<int>, int &&)); |
| 4730 |
static_assert(__is_same(add_rvalue_reference_t<const int>, const int &&)); |
| 4731 |
static_assert(__is_same(add_rvalue_reference_t<volatile int>, volatile int &&)); |
| 4732 |
static_assert(__is_same(add_rvalue_reference_t<const volatile int>, const volatile int &&)); |
| 4733 |
static_assert(__is_same(add_rvalue_reference_t<int *>, int *&&)); |
| 4734 |
static_assert(__is_same(add_rvalue_reference_t<int &>, int &)); // reference collapsing |
| 4735 |
static_assert(__is_same(add_rvalue_reference_t<int &&>, int &&)); |
| 4736 |
static_assert(__is_same(add_rvalue_reference_t<int()>, int(&&)())); |
| 4737 |
static_assert(__is_same(add_rvalue_reference_t<int (*)()>, int (*&&)())); |
| 4738 |
static_assert(__is_same(add_rvalue_reference_t<int (&)()>, int (&)())); // reference collapsing |
| 4739 |
|
| 4740 |
static_assert(__is_same(add_rvalue_reference_t<S>, S &&)); |
| 4741 |
static_assert(__is_same(add_rvalue_reference_t<const S>, const S &&)); |
| 4742 |
static_assert(__is_same(add_rvalue_reference_t<volatile S>, volatile S &&)); |
| 4743 |
static_assert(__is_same(add_rvalue_reference_t<const volatile S>, const volatile S &&)); |
| 4744 |
static_assert(__is_same(add_rvalue_reference_t<int S::*>, int S::*&&)); |
| 4745 |
static_assert(__is_same(add_rvalue_reference_t<int (S::*)()>, int(S::* &&)())); |
| 4746 |
} |
| 4747 |
|
| 4748 |
template <class T> using remove_reference_t = __remove_reference_t(T); |
| 4749 |
|
| 4750 |
void check_remove_reference() { |
| 4751 |
static_assert(__is_same(remove_reference_t<void>, void)); |
| 4752 |
static_assert(__is_same(remove_reference_t<const volatile void>, const volatile void)); |
| 4753 |
static_assert(__is_same(remove_reference_t<int>, int)); |
| 4754 |
static_assert(__is_same(remove_reference_t<const int>, const int)); |
| 4755 |
static_assert(__is_same(remove_reference_t<volatile int>, volatile int)); |
| 4756 |
static_assert(__is_same(remove_reference_t<const volatile int>, const volatile int)); |
| 4757 |
static_assert(__is_same(remove_reference_t<int *>, int *)); |
| 4758 |
static_assert(__is_same(remove_reference_t<int *const volatile>, int *const volatile)); |
| 4759 |
static_assert(__is_same(remove_reference_t<int const *const volatile>, int const *const volatile)); |
| 4760 |
static_assert(__is_same(remove_reference_t<int &>, int)); |
| 4761 |
static_assert(__is_same(remove_reference_t<int const volatile &>, int const volatile)); |
| 4762 |
static_assert(__is_same(remove_reference_t<int &&>, int)); |
| 4763 |
static_assert(__is_same(remove_reference_t<int const volatile &&>, int const volatile)); |
| 4764 |
static_assert(__is_same(remove_reference_t<int()>, int())); |
| 4765 |
static_assert(__is_same(remove_reference_t<int (*const volatile)()>, int (*const volatile)())); |
| 4766 |
static_assert(__is_same(remove_reference_t<int (&)()>, int())); |
| 4767 |
|
| 4768 |
static_assert(__is_same(remove_reference_t<S>, S)); |
| 4769 |
static_assert(__is_same(remove_reference_t<S &>, S)); |
| 4770 |
static_assert(__is_same(remove_reference_t<S &&>, S)); |
| 4771 |
static_assert(__is_same(remove_reference_t<const S>, const S)); |
| 4772 |
static_assert(__is_same(remove_reference_t<const S &>, const S)); |
| 4773 |
static_assert(__is_same(remove_reference_t<const S &&>, const S)); |
| 4774 |
static_assert(__is_same(remove_reference_t<volatile S>, volatile S)); |
| 4775 |
static_assert(__is_same(remove_reference_t<volatile S &>, volatile S)); |
| 4776 |
static_assert(__is_same(remove_reference_t<volatile S &&>, volatile S)); |
| 4777 |
static_assert(__is_same(remove_reference_t<const volatile S>, const volatile S)); |
| 4778 |
static_assert(__is_same(remove_reference_t<const volatile S &>, const volatile S)); |
| 4779 |
static_assert(__is_same(remove_reference_t<const volatile S &&>, const volatile S)); |
| 4780 |
static_assert(__is_same(remove_reference_t<int S::*const volatile &>, int S::*const volatile)); |
| 4781 |
static_assert(__is_same(remove_reference_t<int (S::*const volatile &)()>, int(S::*const volatile)())); |
| 4782 |
static_assert(__is_same(remove_reference_t<int (S::*const volatile &&)() &>, int(S::*const volatile)() &)); |
| 4783 |
} |
| 4784 |
|
| 4785 |
template <class T> using remove_cvref_t = __remove_cvref(T); |
| 4786 |
|
| 4787 |
void check_remove_cvref() { |
| 4788 |
static_assert(__is_same(remove_cvref_t<void>, void)); |
| 4789 |
static_assert(__is_same(remove_cvref_t<const volatile void>, void)); |
| 4790 |
static_assert(__is_same(remove_cvref_t<int>, int)); |
| 4791 |
static_assert(__is_same(remove_cvref_t<const int>, int)); |
| 4792 |
static_assert(__is_same(remove_cvref_t<volatile int>, int)); |
| 4793 |
static_assert(__is_same(remove_cvref_t<const volatile int>, int)); |
| 4794 |
static_assert(__is_same(remove_cvref_t<int *>, int *)); |
| 4795 |
static_assert(__is_same(remove_cvref_t<int *const volatile>, int *)); |
| 4796 |
static_assert(__is_same(remove_cvref_t<int const *const volatile>, int const *)); |
| 4797 |
static_assert(__is_same(remove_cvref_t<int const *const volatile __restrict>, int const *__restrict)); |
| 4798 |
static_assert(__is_same(remove_cvref_t<int const *const volatile _Nonnull>, int const *_Nonnull)); |
| 4799 |
static_assert(__is_same(remove_cvref_t<int &>, int)); |
| 4800 |
static_assert(__is_same(remove_cvref_t<int const volatile &>, int)); |
| 4801 |
static_assert(__is_same(remove_cvref_t<int &&>, int)); |
| 4802 |
static_assert(__is_same(remove_cvref_t<int const volatile &&>, int)); |
| 4803 |
static_assert(__is_same(remove_cvref_t<int()>, int())); |
| 4804 |
static_assert(__is_same(remove_cvref_t<int (*const volatile)()>, int (*)())); |
| 4805 |
static_assert(__is_same(remove_cvref_t<int (&)()>, int())); |
| 4806 |
|
| 4807 |
static_assert(__is_same(remove_cvref_t<S>, S)); |
| 4808 |
static_assert(__is_same(remove_cvref_t<S &>, S)); |
| 4809 |
static_assert(__is_same(remove_cvref_t<S &&>, S)); |
| 4810 |
static_assert(__is_same(remove_cvref_t<const S>, S)); |
| 4811 |
static_assert(__is_same(remove_cvref_t<const S &>, S)); |
| 4812 |
static_assert(__is_same(remove_cvref_t<const S &&>, S)); |
| 4813 |
static_assert(__is_same(remove_cvref_t<volatile S>, S)); |
| 4814 |
static_assert(__is_same(remove_cvref_t<volatile S &>, S)); |
| 4815 |
static_assert(__is_same(remove_cvref_t<volatile S &&>, S)); |
| 4816 |
static_assert(__is_same(remove_cvref_t<const volatile S>, S)); |
| 4817 |
static_assert(__is_same(remove_cvref_t<const volatile S &>, S)); |
| 4818 |
static_assert(__is_same(remove_cvref_t<const volatile S &&>, S)); |
| 4819 |
static_assert(__is_same(remove_cvref_t<int S::*const volatile>, int S::*)); |
| 4820 |
static_assert(__is_same(remove_cvref_t<int (S::*const volatile)()>, int(S::*)())); |
| 4821 |
static_assert(__is_same(remove_cvref_t<int (S::*const volatile)() &>, int(S::*)() &)); |
| 4822 |
static_assert(__is_same(remove_cvref_t<int (S::*const volatile)() &&>, int(S::*)() &&)); |
| 4823 |
} |
| 4824 |
|
| 4825 |
template <class T> using decay_t = __decay(T); |
| 4826 |
|
| 4827 |
void check_decay() { |
| 4828 |
static_assert(__is_same(decay_t<void>, void)); |
| 4829 |
static_assert(__is_same(decay_t<const volatile void>, void)); |
| 4830 |
static_assert(__is_same(decay_t<int>, int)); |
| 4831 |
static_assert(__is_same(decay_t<const int>, int)); |
| 4832 |
static_assert(__is_same(decay_t<volatile int>, int)); |
| 4833 |
static_assert(__is_same(decay_t<const volatile int>, int)); |
| 4834 |
static_assert(__is_same(decay_t<int *>, int *)); |
| 4835 |
static_assert(__is_same(decay_t<int *const volatile>, int *)); |
| 4836 |
static_assert(__is_same(decay_t<int *const volatile __restrict>, int *)); |
| 4837 |
static_assert(__is_same(decay_t<int const *const volatile>, int const *)); |
| 4838 |
static_assert(__is_same(decay_t<int const *const volatile _Nonnull>, int const *)); |
| 4839 |
static_assert(__is_same(decay_t<int &>, int)); |
| 4840 |
static_assert(__is_same(decay_t<int const volatile &>, int)); |
| 4841 |
static_assert(__is_same(decay_t<int &&>, int)); |
| 4842 |
static_assert(__is_same(decay_t<int const volatile &&>, int)); |
| 4843 |
static_assert(__is_same(decay_t<int()>, int (*)())); |
| 4844 |
static_assert(__is_same(decay_t<int (*)()>, int (*)())); |
| 4845 |
static_assert(__is_same(decay_t<int (*const)()>, int (*)())); |
| 4846 |
static_assert(__is_same(decay_t<int (*volatile)()>, int (*)())); |
| 4847 |
static_assert(__is_same(decay_t<int (*const volatile)()>, int (*)())); |
| 4848 |
static_assert(__is_same(decay_t<int (&)()>, int (*)())); |
| 4849 |
static_assert(__is_same(decay_t<IntAr>, int *)); |
| 4850 |
static_assert(__is_same(decay_t<IntArNB>, int *)); |
| 4851 |
|
| 4852 |
static_assert(__is_same(decay_t<S>, S)); |
| 4853 |
static_assert(__is_same(decay_t<S &>, S)); |
| 4854 |
static_assert(__is_same(decay_t<S &&>, S)); |
| 4855 |
static_assert(__is_same(decay_t<const S>, S)); |
| 4856 |
static_assert(__is_same(decay_t<const S &>, S)); |
| 4857 |
static_assert(__is_same(decay_t<const S &&>, S)); |
| 4858 |
static_assert(__is_same(decay_t<volatile S>, S)); |
| 4859 |
static_assert(__is_same(decay_t<volatile S &>, S)); |
| 4860 |
static_assert(__is_same(decay_t<volatile S &&>, S)); |
| 4861 |
static_assert(__is_same(decay_t<const volatile S>, S)); |
| 4862 |
static_assert(__is_same(decay_t<const volatile S &>, S)); |
| 4863 |
static_assert(__is_same(decay_t<const volatile S &&>, S)); |
| 4864 |
static_assert(__is_same(decay_t<int S::*const volatile>, int S::*)); |
| 4865 |
static_assert(__is_same(decay_t<int (S::*const volatile)()>, int(S::*)())); |
| 4866 |
static_assert(__is_same(decay_t<int S::*const volatile &>, int S::*)); |
| 4867 |
static_assert(__is_same(decay_t<int (S::*const volatile &)()>, int(S::*)())); |
| 4868 |
static_assert(__is_same(decay_t<int S::*const volatile &&>, int S::*)); |
| 4869 |
} |
| 4870 |
|
| 4871 |
template <class T> struct CheckAbominableFunction {}; |
| 4872 |
template <class M> |
| 4873 |
struct CheckAbominableFunction<M S::*> { |
| 4874 |
static void checks() { |
| 4875 |
static_assert(__is_same(add_lvalue_reference_t<M>, M)); |
| 4876 |
static_assert(__is_same(add_pointer_t<M>, M)); |
| 4877 |
static_assert(__is_same(add_rvalue_reference_t<M>, M)); |
| 4878 |
static_assert(__is_same(decay_t<M>, M)); |
| 4879 |
static_assert(__is_same(remove_const_t<M>, M)); |
| 4880 |
static_assert(__is_same(remove_volatile_t<M>, M)); |
| 4881 |
static_assert(__is_same(remove_cv_t<M>, M)); |
| 4882 |
static_assert(__is_same(remove_cvref_t<M>, M)); |
| 4883 |
static_assert(__is_same(remove_pointer_t<M>, M)); |
| 4884 |
static_assert(__is_same(remove_reference_t<M>, M)); |
| 4885 |
} |
| 4886 |
}; |
| 4887 |
|
| 4888 |
void check_abominable_function() { |
| 4889 |
{ CheckAbominableFunction<int (S::*)() &> x; } |
| 4890 |
{ CheckAbominableFunction<int (S::*)() &&> x; } |
| 4891 |
{ CheckAbominableFunction<int (S::*)() const> x; } |
| 4892 |
{ CheckAbominableFunction<int (S::*)() const &> x; } |
| 4893 |
{ CheckAbominableFunction<int (S::*)() const &&> x; } |
| 4894 |
{ CheckAbominableFunction<int (S::*)() volatile> x; } |
| 4895 |
{ CheckAbominableFunction<int (S::*)() volatile &> x; } |
| 4896 |
{ CheckAbominableFunction<int (S::*)() volatile &&> x; } |
| 4897 |
{ CheckAbominableFunction<int (S::*)() const volatile> x; } |
| 4898 |
{ CheckAbominableFunction<int (S::*)() const volatile &> x; } |
| 4899 |
{ CheckAbominableFunction<int (S::*)() const volatile &&> x; } |
| 4900 |
} |
| 4901 |
|
| 4902 |
template <class T> using make_signed_t = __make_signed(T); |
| 4903 |
template <class T, class Expected> |
| 4904 |
void check_make_signed() { |
| 4905 |
static_assert(__is_same(make_signed_t<T>, Expected)); |
| 4906 |
static_assert(__is_same(make_signed_t<const T>, const Expected)); |
| 4907 |
static_assert(__is_same(make_signed_t<volatile T>, volatile Expected)); |
| 4908 |
static_assert(__is_same(make_signed_t<const volatile T>, const volatile Expected)); |
| 4909 |
} |
| 4910 |
|
| 4911 |
#if defined(__ILP32__) || defined(__LLP64__) |
| 4912 |
using Int64 = long long; |
| 4913 |
using UInt64 = unsigned long long; |
| 4914 |
#elif defined(__LP64__) || defined(__ILP64__) || defined(__SILP64__) |
| 4915 |
using Int64 = long; |
| 4916 |
using UInt64 = unsigned long; |
| 4917 |
#else |
| 4918 |
#error Programming model currently unsupported; please add a new entry. |
| 4919 |
#endif |
| 4920 |
|
| 4921 |
enum UnscopedBool : bool {}; // deliberately char |
| 4922 |
enum class ScopedBool : bool {}; // deliberately char |
| 4923 |
enum UnscopedChar : char {}; // deliberately char |
| 4924 |
enum class ScopedChar : char {}; // deliberately char |
| 4925 |
enum UnscopedUChar : unsigned char {}; |
| 4926 |
enum class ScopedUChar : unsigned char {}; |
| 4927 |
enum UnscopedLongLong : long long {}; |
| 4928 |
enum UnscopedULongLong : unsigned long long {}; |
| 4929 |
enum class ScopedLongLong : long long {}; |
| 4930 |
enum class ScopedULongLong : unsigned long long {}; |
| 4931 |
enum class UnscopedInt128 : __int128 {}; |
| 4932 |
enum class ScopedInt128 : __int128 {}; |
| 4933 |
enum class UnscopedUInt128 : unsigned __int128 {}; |
| 4934 |
enum class ScopedUInt128 : unsigned __int128 {}; |
| 4935 |
|
| 4936 |
void make_signed() { |
| 4937 |
check_make_signed<char, signed char>(); |
| 4938 |
check_make_signed<signed char, signed char>(); |
| 4939 |
check_make_signed<unsigned char, signed char>(); |
| 4940 |
check_make_signed<short, short>(); |
| 4941 |
check_make_signed<unsigned short, short>(); |
| 4942 |
check_make_signed<int, int>(); |
| 4943 |
check_make_signed<unsigned int, int>(); |
| 4944 |
check_make_signed<long, long>(); |
| 4945 |
check_make_signed<unsigned long, long>(); |
| 4946 |
check_make_signed<long long, long long>(); |
| 4947 |
check_make_signed<unsigned long long, long long>(); |
| 4948 |
check_make_signed<__int128, __int128>(); |
| 4949 |
check_make_signed<__uint128_t, __int128>(); |
| 4950 |
check_make_signed<_BitInt(65), _BitInt(65)>(); |
| 4951 |
check_make_signed<unsigned _BitInt(65), _BitInt(65)>(); |
| 4952 |
|
| 4953 |
check_make_signed<wchar_t, int>(); |
| 4954 |
#if __cplusplus >= 202002L |
| 4955 |
check_make_signed<char8_t, signed char>(); |
| 4956 |
#endif |
| 4957 |
#if __cplusplus >= 201103L |
| 4958 |
check_make_signed<char16_t, short>(); |
| 4959 |
check_make_signed<char32_t, int>(); |
| 4960 |
#endif |
| 4961 |
|
| 4962 |
check_make_signed<UnscopedChar, signed char>(); |
| 4963 |
check_make_signed<ScopedChar, signed char>(); |
| 4964 |
check_make_signed<UnscopedUChar, signed char>(); |
| 4965 |
check_make_signed<ScopedUChar, signed char>(); |
| 4966 |
|
| 4967 |
check_make_signed<UnscopedLongLong, Int64>(); |
| 4968 |
check_make_signed<UnscopedULongLong, Int64>(); |
| 4969 |
check_make_signed<ScopedLongLong, Int64>(); |
| 4970 |
check_make_signed<ScopedULongLong, Int64>(); |
| 4971 |
|
| 4972 |
check_make_signed<UnscopedInt128, __int128>(); |
| 4973 |
check_make_signed<ScopedInt128, __int128>(); |
| 4974 |
check_make_signed<UnscopedUInt128, __int128>(); |
| 4975 |
check_make_signed<ScopedUInt128, __int128>(); |
| 4976 |
|
| 4977 |
{ using ExpectedError = __make_signed(bool); } |
| 4978 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'bool'}} |
| 4979 |
{ using ExpectedError = __make_signed(UnscopedBool); } |
| 4980 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'UnscopedBool' whose underlying type is 'bool'}} |
| 4981 |
{ using ExpectedError = __make_signed(ScopedBool); } |
| 4982 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'ScopedBool' whose underlying type is 'bool'}} |
| 4983 |
{ using ExpectedError = __make_signed(unsigned _BitInt(1)); } |
| 4984 |
// expected-error@*:*{{'make_signed' is only compatible with non-_BitInt(1) integers and enum types, but was given 'unsigned _BitInt(1)'}} |
| 4985 |
{ using ExpectedError = __make_signed(int[]); } |
| 4986 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'int[]'}} |
| 4987 |
{ using ExpectedError = __make_signed(int[5]); } |
| 4988 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'int[5]'}} |
| 4989 |
{ using ExpectedError = __make_signed(void); } |
| 4990 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'void'}} |
| 4991 |
{ using ExpectedError = __make_signed(int *); } |
| 4992 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'int *'}} |
| 4993 |
{ using ExpectedError = __make_signed(int &); } |
| 4994 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'int &'}} |
| 4995 |
{ using ExpectedError = __make_signed(int &&); } |
| 4996 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'int &&'}} |
| 4997 |
{ using ExpectedError = __make_signed(float); } |
| 4998 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'float'}} |
| 4999 |
{ using ExpectedError = __make_signed(double); } |
| 5000 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'double'}} |
| 5001 |
{ using ExpectedError = __make_signed(long double); } |
| 5002 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'long double'}} |
| 5003 |
{ using ExpectedError = __make_signed(S); } |
| 5004 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'S'}} |
| 5005 |
{ using ExpectedError = __make_signed(S *); } |
| 5006 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'S *'}} |
| 5007 |
{ using ExpectedError = __make_signed(int S::*); } |
| 5008 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'int S::*'}} |
| 5009 |
{ using ExpectedError = __make_signed(int(S::*)()); } |
| 5010 |
// expected-error@*:*{{'make_signed' is only compatible with non-bool integers and enum types, but was given 'int (S::*)()'}} |
| 5011 |
} |
| 5012 |
|
| 5013 |
template <class T> |
| 5014 |
using make_unsigned_t = __make_unsigned(T); |
| 5015 |
|
| 5016 |
template <class T, class Expected> |
| 5017 |
void check_make_unsigned() { |
| 5018 |
static_assert(__is_same(make_unsigned_t<T>, Expected)); |
| 5019 |
static_assert(__is_same(make_unsigned_t<const T>, const Expected)); |
| 5020 |
static_assert(__is_same(make_unsigned_t<volatile T>, volatile Expected)); |
| 5021 |
static_assert(__is_same(make_unsigned_t<const volatile T>, const volatile Expected)); |
| 5022 |
} |
| 5023 |
|
| 5024 |
void make_unsigned() { |
| 5025 |
check_make_unsigned<char, unsigned char>(); |
| 5026 |
check_make_unsigned<signed char, unsigned char>(); |
| 5027 |
check_make_unsigned<unsigned char, unsigned char>(); |
| 5028 |
check_make_unsigned<short, unsigned short>(); |
| 5029 |
check_make_unsigned<unsigned short, unsigned short>(); |
| 5030 |
check_make_unsigned<int, unsigned int>(); |
| 5031 |
check_make_unsigned<unsigned int, unsigned int>(); |
| 5032 |
check_make_unsigned<long, unsigned long>(); |
| 5033 |
check_make_unsigned<unsigned long, unsigned long>(); |
| 5034 |
check_make_unsigned<long long, unsigned long long>(); |
| 5035 |
check_make_unsigned<unsigned long long, unsigned long long>(); |
| 5036 |
check_make_unsigned<__int128, __uint128_t>(); |
| 5037 |
check_make_unsigned<__uint128_t, __uint128_t>(); |
| 5038 |
check_make_unsigned<_BitInt(65), unsigned _BitInt(65)>(); |
| 5039 |
check_make_unsigned<unsigned _BitInt(65), unsigned _BitInt(65)>(); |
| 5040 |
|
| 5041 |
check_make_unsigned<wchar_t, unsigned int>(); |
| 5042 |
#if __cplusplus >= 202002L |
| 5043 |
check_make_unsigned<char8_t, unsigned char>(); |
| 5044 |
#endif |
| 5045 |
#if __cplusplus >= 201103L |
| 5046 |
check_make_unsigned<char16_t, unsigned short>(); |
| 5047 |
check_make_unsigned<char32_t, unsigned int>(); |
| 5048 |
#endif |
| 5049 |
|
| 5050 |
check_make_unsigned<UnscopedChar, unsigned char>(); |
| 5051 |
check_make_unsigned<ScopedChar, unsigned char>(); |
| 5052 |
check_make_unsigned<UnscopedUChar, unsigned char>(); |
| 5053 |
check_make_unsigned<ScopedUChar, unsigned char>(); |
| 5054 |
|
| 5055 |
check_make_unsigned<UnscopedLongLong, UInt64>(); |
| 5056 |
check_make_unsigned<UnscopedULongLong, UInt64>(); |
| 5057 |
check_make_unsigned<ScopedLongLong, UInt64>(); |
| 5058 |
check_make_unsigned<ScopedULongLong, UInt64>(); |
| 5059 |
|
| 5060 |
check_make_unsigned<UnscopedInt128, unsigned __int128>(); |
| 5061 |
check_make_unsigned<ScopedInt128, unsigned __int128>(); |
| 5062 |
check_make_unsigned<UnscopedUInt128, unsigned __int128>(); |
| 5063 |
check_make_unsigned<ScopedUInt128, unsigned __int128>(); |
| 5064 |
|
| 5065 |
{ using ExpectedError = __make_unsigned(bool); } |
| 5066 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'bool'}} |
| 5067 |
{ using ExpectedError = __make_unsigned(UnscopedBool); } |
| 5068 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'UnscopedBool' whose underlying type is 'bool'}} |
| 5069 |
{ using ExpectedError = __make_unsigned(ScopedBool); } |
| 5070 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'ScopedBool' whose underlying type is 'bool'}} |
| 5071 |
{ using ExpectedError = __make_unsigned(unsigned _BitInt(1)); } |
| 5072 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-_BitInt(1) integers and enum types, but was given 'unsigned _BitInt(1)'}} |
| 5073 |
{ using ExpectedError = __make_unsigned(int[]); } |
| 5074 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'int[]'}} |
| 5075 |
{ using ExpectedError = __make_unsigned(int[5]); } |
| 5076 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'int[5]'}} |
| 5077 |
{ using ExpectedError = __make_unsigned(void); } |
| 5078 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'void'}} |
| 5079 |
{ using ExpectedError = __make_unsigned(int *); } |
| 5080 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'int *'}} |
| 5081 |
{ using ExpectedError = __make_unsigned(int &); } |
| 5082 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'int &'}} |
| 5083 |
{ using ExpectedError = __make_unsigned(int &&); } |
| 5084 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'int &&'}} |
| 5085 |
{ using ExpectedError = __make_unsigned(float); } |
| 5086 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'float'}} |
| 5087 |
{ using ExpectedError = __make_unsigned(double); } |
| 5088 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'double'}} |
| 5089 |
{ using ExpectedError = __make_unsigned(long double); } |
| 5090 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'long double'}} |
| 5091 |
{ using ExpectedError = __make_unsigned(S); } |
| 5092 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'S'}} |
| 5093 |
{ using ExpectedError = __make_unsigned(S *); } |
| 5094 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'S *'}} |
| 5095 |
{ using ExpectedError = __make_unsigned(int S::*); } |
| 5096 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'int S::*'}} |
| 5097 |
{ using ExpectedError = __make_unsigned(int(S::*)()); } |
| 5098 |
// expected-error@*:*{{'make_unsigned' is only compatible with non-bool integers and enum types, but was given 'int (S::*)()'}} |
| 5099 |
} |
| 5100 |
|
| 5101 |
template <class T> using remove_extent_t = __remove_extent(T); |
| 5102 |
|
| 5103 |
void remove_extent() { |
| 5104 |
static_assert(__is_same(remove_extent_t<void>, void)); |
| 5105 |
static_assert(__is_same(remove_extent_t<int>, int)); |
| 5106 |
static_assert(__is_same(remove_extent_t<int[]>, int)); |
| 5107 |
static_assert(__is_same(remove_extent_t<int[1]>, int)); |
| 5108 |
static_assert(__is_same(remove_extent_t<int[1][2]>, int[2])); |
| 5109 |
static_assert(__is_same(remove_extent_t<int[][2]>, int[2])); |
| 5110 |
static_assert(__is_same(remove_extent_t<const int[]>, const int)); |
| 5111 |
static_assert(__is_same(remove_extent_t<const int[1]>, const int)); |
| 5112 |
static_assert(__is_same(remove_extent_t<const int[1][2]>, const int[2])); |
| 5113 |
static_assert(__is_same(remove_extent_t<const int[][2]>, const int[2])); |
| 5114 |
static_assert(__is_same(remove_extent_t<volatile int[]>, volatile int)); |
| 5115 |
static_assert(__is_same(remove_extent_t<volatile int[1]>, volatile int)); |
| 5116 |
static_assert(__is_same(remove_extent_t<volatile int[1][2]>, volatile int[2])); |
| 5117 |
static_assert(__is_same(remove_extent_t<volatile int[][2]>, volatile int[2])); |
| 5118 |
static_assert(__is_same(remove_extent_t<const volatile int[]>, const volatile int)); |
| 5119 |
static_assert(__is_same(remove_extent_t<const volatile int[1]>, const volatile int)); |
| 5120 |
static_assert(__is_same(remove_extent_t<const volatile int[1][2]>, const volatile int[2])); |
| 5121 |
static_assert(__is_same(remove_extent_t<const volatile int[][2]>, const volatile int[2])); |
| 5122 |
static_assert(__is_same(remove_extent_t<int *>, int *)); |
| 5123 |
static_assert(__is_same(remove_extent_t<int &>, int &)); |
| 5124 |
static_assert(__is_same(remove_extent_t<int &&>, int &&)); |
| 5125 |
static_assert(__is_same(remove_extent_t<int()>, int())); |
| 5126 |
static_assert(__is_same(remove_extent_t<int (*)()>, int (*)())); |
| 5127 |
static_assert(__is_same(remove_extent_t<int (&)()>, int (&)())); |
| 5128 |
|
| 5129 |
static_assert(__is_same(remove_extent_t<S>, S)); |
| 5130 |
static_assert(__is_same(remove_extent_t<int S::*>, int S::*)); |
| 5131 |
static_assert(__is_same(remove_extent_t<int (S::*)()>, int(S::*)())); |
| 5132 |
|
| 5133 |
using SomeArray = int[1][2]; |
| 5134 |
static_assert(__is_same(remove_extent_t<const SomeArray>, const int[2])); |
| 5135 |
} |
| 5136 |
|
| 5137 |
template <class T> using remove_all_extents_t = __remove_all_extents(T); |
| 5138 |
|
| 5139 |
void remove_all_extents() { |
| 5140 |
static_assert(__is_same(remove_all_extents_t<void>, void)); |
| 5141 |
static_assert(__is_same(remove_all_extents_t<int>, int)); |
| 5142 |
static_assert(__is_same(remove_all_extents_t<const int>, const int)); |
| 5143 |
static_assert(__is_same(remove_all_extents_t<volatile int>, volatile int)); |
| 5144 |
static_assert(__is_same(remove_all_extents_t<const volatile int>, const volatile int)); |
| 5145 |
static_assert(__is_same(remove_all_extents_t<int[]>, int)); |
| 5146 |
static_assert(__is_same(remove_all_extents_t<int[1]>, int)); |
| 5147 |
static_assert(__is_same(remove_all_extents_t<int[1][2]>, int)); |
| 5148 |
static_assert(__is_same(remove_all_extents_t<int[][2]>, int)); |
| 5149 |
static_assert(__is_same(remove_all_extents_t<const int[]>, const int)); |
| 5150 |
static_assert(__is_same(remove_all_extents_t<const int[1]>, const int)); |
| 5151 |
static_assert(__is_same(remove_all_extents_t<const int[1][2]>, const int)); |
| 5152 |
static_assert(__is_same(remove_all_extents_t<const int[][2]>, const int)); |
| 5153 |
static_assert(__is_same(remove_all_extents_t<volatile int[]>, volatile int)); |
| 5154 |
static_assert(__is_same(remove_all_extents_t<volatile int[1]>, volatile int)); |
| 5155 |
static_assert(__is_same(remove_all_extents_t<volatile int[1][2]>, volatile int)); |
| 5156 |
static_assert(__is_same(remove_all_extents_t<volatile int[][2]>, volatile int)); |
| 5157 |
static_assert(__is_same(remove_all_extents_t<const volatile int[]>, const volatile int)); |
| 5158 |
static_assert(__is_same(remove_all_extents_t<const volatile int[1]>, const volatile int)); |
| 5159 |
static_assert(__is_same(remove_all_extents_t<const volatile int[1][2]>, const volatile int)); |
| 5160 |
static_assert(__is_same(remove_all_extents_t<const volatile int[][2]>, const volatile int)); |
| 5161 |
static_assert(__is_same(remove_all_extents_t<int *>, int *)); |
| 5162 |
static_assert(__is_same(remove_all_extents_t<int &>, int &)); |
| 5163 |
static_assert(__is_same(remove_all_extents_t<int &&>, int &&)); |
| 5164 |
static_assert(__is_same(remove_all_extents_t<int()>, int())); |
| 5165 |
static_assert(__is_same(remove_all_extents_t<int (*)()>, int (*)())); |
| 5166 |
static_assert(__is_same(remove_all_extents_t<int (&)()>, int (&)())); |
| 5167 |
|
| 5168 |
static_assert(__is_same(remove_all_extents_t<S>, S)); |
| 5169 |
static_assert(__is_same(remove_all_extents_t<int S::*>, int S::*)); |
| 5170 |
static_assert(__is_same(remove_all_extents_t<int (S::*)()>, int(S::*)())); |
| 5171 |
|
| 5172 |
using SomeArray = int[1][2]; |
| 5173 |
static_assert(__is_same(remove_all_extents_t<const SomeArray>, const int)); |
| 5174 |
} |
| 5175 |
|
| 5176 |
namespace GH121278 { |
| 5177 |
// https://cplusplus.github.io/LWG/lwg-active.html#3929 |
| 5178 |
#if __cplusplus >= 202002L |
| 5179 |
template <typename B, typename D> |
| 5180 |
concept C = __is_base_of(B, D); |
| 5181 |
// expected-error@-1 {{incomplete type 'S' used in type trait expression}} |
| 5182 |
// expected-note@-2 {{while substituting template arguments into constraint expression here}} |
| 5183 |
|
| 5184 |
struct T; |
| 5185 |
struct S; |
| 5186 |
bool b = C<T, S>; |
| 5187 |
// expected-note@-1 {{while checking the satisfaction of concept 'C<T, S>' requested here}} |
| 5188 |
#endif |
| 5189 |
} |