1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "mozilla/Assertions.h"
8 #include "mozilla/TypeTraits.h"
10 #define TEST_CV_QUALIFIERS(test, type, ...) \
11 test(type, __VA_ARGS__) test(const type, __VA_ARGS__) \
12 test(volatile type, __VA_ARGS__) test(const volatile type, __VA_ARGS__)
14 using mozilla::AddLvalueReference
;
15 using mozilla::AddPointer
;
16 using mozilla::AddRvalueReference
;
18 using mozilla::DeclVal
;
19 using mozilla::IsArray
;
20 using mozilla::IsBaseOf
;
21 using mozilla::IsClass
;
22 using mozilla::IsConvertible
;
23 using mozilla::IsDefaultConstructible
;
24 using mozilla::IsDestructible
;
25 using mozilla::IsEmpty
;
26 using mozilla::IsFunction
;
27 using mozilla::IsLvalueReference
;
28 using mozilla::IsPointer
;
29 using mozilla::IsReference
;
30 using mozilla::IsRvalueReference
;
31 using mozilla::IsSame
;
32 using mozilla::IsSigned
;
33 using mozilla::IsUnsigned
;
34 using mozilla::MakeSigned
;
35 using mozilla::MakeUnsigned
;
36 using mozilla::RemoveExtent
;
37 using mozilla::RemovePointer
;
39 static_assert(!IsFunction
<int>::value
, "int is not a function type");
40 static_assert(IsFunction
<void(int)>::value
, "void(int) is a function type");
41 static_assert(!IsFunction
<void (*)(int)>::value
,
42 "void(*)(int) is not a function type");
44 static_assert(!IsArray
<bool>::value
, "bool not an array");
45 static_assert(IsArray
<bool[]>::value
, "bool[] is an array");
46 static_assert(IsArray
<bool[5]>::value
, "bool[5] is an array");
48 static_assert(!IsPointer
<bool>::value
, "bool not a pointer");
49 static_assert(IsPointer
<bool*>::value
, "bool* is a pointer");
50 static_assert(IsPointer
<bool* const>::value
, "bool* const is a pointer");
51 static_assert(IsPointer
<bool* volatile>::value
, "bool* volatile is a pointer");
52 static_assert(IsPointer
<bool* const volatile>::value
,
53 "bool* const volatile is a pointer");
54 static_assert(IsPointer
<bool**>::value
, "bool** is a pointer");
55 static_assert(IsPointer
<void (*)(void)>::value
, "void (*)(void) is a pointer");
56 struct IsPointerTest
{
60 static_assert(!IsPointer
<IsPointerTest
>::value
, "IsPointerTest not a pointer");
61 static_assert(IsPointer
<IsPointerTest
*>::value
, "IsPointerTest* is a pointer");
62 static_assert(!IsPointer
<bool (IsPointerTest::*)()>::value
,
63 "bool(IsPointerTest::*)() not a pointer");
64 static_assert(!IsPointer
<void (IsPointerTest::*)(void)>::value
,
65 "void(IsPointerTest::*)(void) not a pointer");
67 static_assert(!IsLvalueReference
<bool>::value
, "bool not an lvalue reference");
68 static_assert(!IsLvalueReference
<bool*>::value
,
69 "bool* not an lvalue reference");
70 static_assert(IsLvalueReference
<bool&>::value
, "bool& is an lvalue reference");
71 static_assert(!IsLvalueReference
<bool&&>::value
,
72 "bool&& not an lvalue reference");
74 static_assert(!IsLvalueReference
<void>::value
, "void not an lvalue reference");
75 static_assert(!IsLvalueReference
<void*>::value
,
76 "void* not an lvalue reference");
78 static_assert(!IsLvalueReference
<int>::value
, "int not an lvalue reference");
79 static_assert(!IsLvalueReference
<int*>::value
, "int* not an lvalue reference");
80 static_assert(IsLvalueReference
<int&>::value
, "int& is an lvalue reference");
81 static_assert(!IsLvalueReference
<int&&>::value
,
82 "int&& not an lvalue reference");
84 static_assert(!IsRvalueReference
<bool>::value
, "bool not an rvalue reference");
85 static_assert(!IsRvalueReference
<bool*>::value
,
86 "bool* not an rvalue reference");
87 static_assert(!IsRvalueReference
<bool&>::value
,
88 "bool& not an rvalue reference");
89 static_assert(IsRvalueReference
<bool&&>::value
,
90 "bool&& is an rvalue reference");
92 static_assert(!IsRvalueReference
<void>::value
, "void not an rvalue reference");
93 static_assert(!IsRvalueReference
<void*>::value
,
94 "void* not an rvalue reference");
96 static_assert(!IsRvalueReference
<int>::value
, "int not an rvalue reference");
97 static_assert(!IsRvalueReference
<int*>::value
, "int* not an rvalue reference");
98 static_assert(!IsRvalueReference
<int&>::value
, "int& not an rvalue reference");
99 static_assert(IsRvalueReference
<int&&>::value
, "int&& is an rvalue reference");
101 static_assert(!IsReference
<bool>::value
, "bool not a reference");
102 static_assert(!IsReference
<bool*>::value
, "bool* not a reference");
103 static_assert(IsReference
<bool&>::value
, "bool& is a reference");
104 static_assert(IsReference
<bool&&>::value
, "bool&& is a reference");
106 static_assert(!IsReference
<void>::value
, "void not a reference");
107 static_assert(!IsReference
<void*>::value
, "void* not a reference");
109 static_assert(!IsReference
<int>::value
, "int not a reference");
110 static_assert(!IsReference
<int*>::value
, "int* not a reference");
111 static_assert(IsReference
<int&>::value
, "int& is a reference");
112 static_assert(IsReference
<int&&>::value
, "int&& is a reference");
114 namespace CPlusPlus11IsMemberPointer
{
116 using mozilla::IsMemberPointer
;
121 #define ASSERT_IS_MEMBER_POINTER(type, msg) \
122 static_assert(IsMemberPointer<type>::value, #type msg);
123 #define TEST_IS_MEMBER_POINTER(type) \
124 TEST_CV_QUALIFIERS(ASSERT_IS_MEMBER_POINTER, type, \
125 " is a member pointer type")
127 TEST_IS_MEMBER_POINTER(int S::*)
128 TEST_IS_MEMBER_POINTER(int U::*)
130 #undef TEST_IS_MEMBER_POINTER
131 #undef ASSERT_IS_MEMBER_POINTER
133 #define ASSERT_IS_NOT_MEMBER_POINTER(type, msg) \
134 static_assert(!IsMemberPointer<type>::value, #type msg);
135 #define TEST_IS_NOT_MEMBER_POINTER(type) \
136 TEST_CV_QUALIFIERS(ASSERT_IS_NOT_MEMBER_POINTER, type, \
137 " is not a member pointer type")
139 TEST_IS_NOT_MEMBER_POINTER(int*)
141 #undef TEST_IS_NOT_MEMBER_POINTER
142 #undef ASSERT_IS_NOT_MEMBER_POINTER
144 } // namespace CPlusPlus11IsMemberPointer
146 namespace CPlusPlus11IsScalar
{
148 using mozilla::IsScalar
;
156 #define ASSERT_IS_SCALAR(type, msg) \
157 static_assert(IsScalar<type>::value, #type msg);
158 #define TEST_IS_SCALAR(type) \
159 TEST_CV_QUALIFIERS(ASSERT_IS_SCALAR, type, " is a scalar type")
162 TEST_IS_SCALAR(float)
166 TEST_IS_SCALAR(int S::*)
168 #undef TEST_IS_SCALAR
169 #undef ASSERT_IS_SCALAR
171 #define ASSERT_IS_NOT_SCALAR(type, msg) \
172 static_assert(!IsScalar<type>::value, #type msg);
173 #define TEST_IS_NOT_SCALAR(type) \
174 TEST_CV_QUALIFIERS(ASSERT_IS_NOT_SCALAR, type, " is not a scalar type")
176 TEST_IS_NOT_SCALAR(C
)
177 TEST_IS_NOT_SCALAR(S
)
178 TEST_IS_NOT_SCALAR(U
)
180 #undef TEST_IS_NOT_SCALAR
181 #undef ASSERT_IS_NOT_SCALAR
183 } // namespace CPlusPlus11IsScalar
190 static_assert(!IsClass
<int>::value
, "int isn't a class");
191 static_assert(IsClass
<const S1
>::value
, "S is a class");
192 static_assert(!IsClass
<U1
>::value
, "U isn't a class");
194 static_assert(!mozilla::IsEmpty
<int>::value
, "not a class => not empty");
195 static_assert(!mozilla::IsEmpty
<bool[5]>::value
, "not a class => not empty");
197 static_assert(!mozilla::IsEmpty
<U1
>::value
, "not a class => not empty");
206 static_assert(IsEmpty
<const volatile S1
>::value
, "S should be empty");
208 static_assert(mozilla::IsEmpty
<E1
>::value
&& mozilla::IsEmpty
<E2
>::value
&&
209 mozilla::IsEmpty
<E3
>::value
&& mozilla::IsEmpty
<E4
>::value
,
215 static_assert(!mozilla::IsEmpty
<U2
>::value
, "not a class => not empty");
220 struct NE2
: virtual E1
{};
228 static_assert(!mozilla::IsEmpty
<NE1
>::value
&& !mozilla::IsEmpty
<NE2
>::value
&&
229 !mozilla::IsEmpty
<NE3
>::value
&&
230 !mozilla::IsEmpty
<NE4
>::value
,
233 static_assert(!IsSigned
<bool>::value
, "bool shouldn't be signed");
234 static_assert(IsUnsigned
<bool>::value
, "bool should be unsigned");
236 static_assert(!IsSigned
<const bool>::value
, "const bool shouldn't be signed");
237 static_assert(IsUnsigned
<const bool>::value
, "const bool should be unsigned");
239 static_assert(!IsSigned
<volatile bool>::value
,
240 "volatile bool shouldn't be signed");
241 static_assert(IsUnsigned
<volatile bool>::value
,
242 "volatile bool should be unsigned");
244 static_assert(!IsSigned
<unsigned char>::value
,
245 "unsigned char shouldn't be signed");
246 static_assert(IsUnsigned
<unsigned char>::value
,
247 "unsigned char should be unsigned");
248 static_assert(IsSigned
<signed char>::value
, "signed char should be signed");
249 static_assert(!IsUnsigned
<signed char>::value
,
250 "signed char shouldn't be unsigned");
252 static_assert(!IsSigned
<unsigned short>::value
,
253 "unsigned short shouldn't be signed");
254 static_assert(IsUnsigned
<unsigned short>::value
,
255 "unsigned short should be unsigned");
256 static_assert(IsSigned
<short>::value
, "short should be signed");
257 static_assert(!IsUnsigned
<short>::value
, "short shouldn't be unsigned");
259 static_assert(!IsSigned
<unsigned int>::value
,
260 "unsigned int shouldn't be signed");
261 static_assert(IsUnsigned
<unsigned int>::value
,
262 "unsigned int should be unsigned");
263 static_assert(IsSigned
<int>::value
, "int should be signed");
264 static_assert(!IsUnsigned
<int>::value
, "int shouldn't be unsigned");
266 static_assert(!IsSigned
<unsigned long>::value
,
267 "unsigned long shouldn't be signed");
268 static_assert(IsUnsigned
<unsigned long>::value
,
269 "unsigned long should be unsigned");
270 static_assert(IsSigned
<long>::value
, "long should be signed");
271 static_assert(!IsUnsigned
<long>::value
, "long shouldn't be unsigned");
273 static_assert(IsSigned
<float>::value
, "float should be signed");
274 static_assert(!IsUnsigned
<float>::value
, "float shouldn't be unsigned");
276 static_assert(IsSigned
<const float>::value
, "const float should be signed");
277 static_assert(!IsUnsigned
<const float>::value
,
278 "const float shouldn't be unsigned");
280 static_assert(IsSigned
<double>::value
, "double should be signed");
281 static_assert(!IsUnsigned
<double>::value
, "double shouldn't be unsigned");
283 static_assert(IsSigned
<volatile double>::value
,
284 "volatile double should be signed");
285 static_assert(!IsUnsigned
<volatile double>::value
,
286 "volatile double shouldn't be unsigned");
288 static_assert(IsSigned
<long double>::value
, "long double should be signed");
289 static_assert(!IsUnsigned
<long double>::value
,
290 "long double shouldn't be unsigned");
292 static_assert(IsSigned
<const volatile long double>::value
,
293 "const volatile long double should be signed");
294 static_assert(!IsUnsigned
<const volatile long double>::value
,
295 "const volatile long double shouldn't be unsigned");
297 class NotIntConstructible
{
298 NotIntConstructible(int) = delete;
301 static_assert(!IsSigned
<NotIntConstructible
>::value
,
302 "non-arithmetic types are not signed");
303 static_assert(!IsUnsigned
<NotIntConstructible
>::value
,
304 "non-arithmetic types are not unsigned");
306 struct TrivialCtor0
{};
307 struct TrivialCtor1
{
311 struct DefaultCtor0
{
314 struct DefaultCtor1
{
315 DefaultCtor1() = default;
317 struct DefaultCtor2
{
319 explicit DefaultCtor2(int) {}
322 struct NoDefaultCtor0
{
323 explicit NoDefaultCtor0(int) {}
325 struct NoDefaultCtor1
{
326 NoDefaultCtor1() = delete;
333 PrivateCtor1() = default;
337 enum EnumCtor1
: int {};
339 enum class EnumClassCtor0
{};
340 enum class EnumClassCtor1
: int {};
347 union UnionCustomCtor0
{
348 explicit UnionCustomCtor0(int) {}
350 union UnionCustomCtor1
{
352 explicit UnionCustomCtor1(int aX
) : mX(aX
) {}
355 static_assert(IsDefaultConstructible
<int>::value
,
356 "integral type is default-constructible");
358 static_assert(IsDefaultConstructible
<TrivialCtor0
>::value
,
359 "trivial constructor class 0 is default-constructible");
360 static_assert(IsDefaultConstructible
<TrivialCtor1
>::value
,
361 "trivial constructor class 1 is default-constructible");
363 static_assert(IsDefaultConstructible
<DefaultCtor0
>::value
,
364 "default constructor class 0 is default-constructible");
365 static_assert(IsDefaultConstructible
<DefaultCtor1
>::value
,
366 "default constructor class 1 is default-constructible");
367 static_assert(IsDefaultConstructible
<DefaultCtor2
>::value
,
368 "default constructor class 2 is default-constructible");
370 static_assert(!IsDefaultConstructible
<NoDefaultCtor0
>::value
,
371 "no default constructor class is not default-constructible");
372 static_assert(!IsDefaultConstructible
<NoDefaultCtor1
>::value
,
373 "deleted default constructor class is not default-constructible");
376 !IsDefaultConstructible
<PrivateCtor0
>::value
,
377 "private default constructor class 0 is not default-constructible");
379 !IsDefaultConstructible
<PrivateCtor1
>::value
,
380 "private default constructor class 1 is not default-constructible");
382 static_assert(IsDefaultConstructible
<EnumCtor0
>::value
,
383 "enum constructor 0 is default-constructible");
384 static_assert(IsDefaultConstructible
<EnumCtor1
>::value
,
385 "enum constructor 1 is default-constructible");
387 static_assert(IsDefaultConstructible
<EnumClassCtor0
>::value
,
388 "enum class constructor 0 is default-constructible");
389 static_assert(IsDefaultConstructible
<EnumClassCtor1
>::value
,
390 "enum class constructor 1 is default-constructible");
392 static_assert(IsDefaultConstructible
<UnionCtor0
>::value
,
393 "union constructor 0 is default-constructible");
394 static_assert(IsDefaultConstructible
<UnionCtor1
>::value
,
395 "union constructor 1 is default-constructible");
398 !IsDefaultConstructible
<UnionCustomCtor0
>::value
,
399 "union with custom 1-arg constructor 0 is not default-constructible");
401 !IsDefaultConstructible
<UnionCustomCtor1
>::value
,
402 "union with custom 1-arg constructor 1 is not default-constructible");
404 class PublicDestructible
{
406 ~PublicDestructible();
408 class PrivateDestructible
{
410 ~PrivateDestructible();
412 class TrivialDestructible
{};
414 static_assert(IsDestructible
<PublicDestructible
>::value
,
415 "public destructible class is destructible");
416 static_assert(!IsDestructible
<PrivateDestructible
>::value
,
417 "private destructible class is not destructible");
418 static_assert(IsDestructible
<TrivialDestructible
>::value
,
419 "trivial destructible class is destructible");
421 namespace CPlusPlus11IsBaseOf
{
423 // Adapted from C++11 § 20.9.6.
427 struct D
: private B1
, private B2
{};
429 static void StandardIsBaseOfTests() {
430 static_assert((IsBaseOf
<B
, D
>::value
) == true, "IsBaseOf fails on diamond");
431 static_assert((IsBaseOf
<const B
, D
>::value
) == true,
432 "IsBaseOf fails on diamond plus constness change");
433 static_assert((IsBaseOf
<B
, const D
>::value
) == true,
434 "IsBaseOf fails on diamond plus constness change");
435 static_assert((IsBaseOf
<B
, const B
>::value
) == true,
436 "IsBaseOf fails on constness change");
437 static_assert((IsBaseOf
<D
, B
>::value
) == false,
438 "IsBaseOf got the direction of inheritance wrong");
439 static_assert((IsBaseOf
<B
&, D
&>::value
) == false,
440 "IsBaseOf should return false on references");
441 static_assert((IsBaseOf
<B
[3], D
[3]>::value
) == false,
442 "IsBaseOf should return false on arrays");
443 // We fail at the following test. To fix it, we need to specialize IsBaseOf
444 // for all built-in types.
445 // static_assert((IsBaseOf<int, int>::value) == false);
448 } /* namespace CPlusPlus11IsBaseOf */
451 class B
: public A
{};
452 class C
: private A
{};
454 class E
: public A
{};
455 class F
: public B
, public E
{};
457 static void TestIsBaseOf() {
458 static_assert((IsBaseOf
<A
, B
>::value
), "A is a base of B");
459 static_assert((!IsBaseOf
<B
, A
>::value
), "B is not a base of A");
460 static_assert((IsBaseOf
<A
, C
>::value
), "A is a base of C");
461 static_assert((!IsBaseOf
<C
, A
>::value
), "C is not a base of A");
462 static_assert((IsBaseOf
<A
, F
>::value
), "A is a base of F");
463 static_assert((!IsBaseOf
<F
, A
>::value
), "F is not a base of A");
464 static_assert((!IsBaseOf
<A
, D
>::value
), "A is not a base of D");
465 static_assert((!IsBaseOf
<D
, A
>::value
), "D is not a base of A");
466 static_assert((IsBaseOf
<B
, B
>::value
),
467 "B is the same as B (and therefore, a base of B)");
470 class ExplicitCopyConstructor
{
471 explicit ExplicitCopyConstructor(const ExplicitCopyConstructor
&) = default;
474 static void TestIsConvertible() {
475 // Pointer type convertibility
476 static_assert((IsConvertible
<A
*, A
*>::value
), "A* should convert to A*");
477 static_assert((IsConvertible
<B
*, A
*>::value
), "B* should convert to A*");
478 static_assert((!IsConvertible
<A
*, B
*>::value
), "A* shouldn't convert to B*");
479 static_assert((!IsConvertible
<A
*, C
*>::value
), "A* shouldn't convert to C*");
480 static_assert((!IsConvertible
<A
*, D
*>::value
),
481 "A* shouldn't convert to unrelated D*");
482 static_assert((!IsConvertible
<D
*, A
*>::value
),
483 "D* shouldn't convert to unrelated A*");
485 // Instance type convertibility
486 static_assert((IsConvertible
<A
, A
>::value
), "A is A");
487 static_assert((IsConvertible
<B
, A
>::value
), "B converts to A");
488 static_assert((!IsConvertible
<D
, A
>::value
), "D and A are unrelated");
489 static_assert((!IsConvertible
<A
, D
>::value
), "A and D are unrelated");
491 static_assert(IsConvertible
<void, void>::value
, "void is void");
492 static_assert(!IsConvertible
<A
, void>::value
, "A shouldn't convert to void");
493 static_assert(!IsConvertible
<void, B
>::value
, "void shouldn't convert to B");
495 static_assert(!IsConvertible
<const ExplicitCopyConstructor
&,
496 ExplicitCopyConstructor
>::value
,
497 "IsConvertible should test for implicit convertibility");
499 // These cases seem to require C++11 support to properly implement them, so
500 // for now just disable them.
501 // static_assert((!IsConvertible<C*, A*>::value),
502 // "C* shouldn't convert to A* (private inheritance)");
503 // static_assert((!IsConvertible<C, A>::value),
504 // "C doesn't convert to A (private inheritance)");
507 static_assert(IsSame
<AddLvalueReference
<int>::Type
, int&>::value
,
508 "not adding & to int correctly");
510 IsSame
<AddLvalueReference
<volatile int&>::Type
, volatile int&>::value
,
511 "not adding & to volatile int& correctly");
512 static_assert(IsSame
<AddLvalueReference
<void*>::Type
, void*&>::value
,
513 "not adding & to void* correctly");
514 static_assert(IsSame
<AddLvalueReference
<void>::Type
, void>::value
,
515 "void shouldn't be transformed by AddLvalueReference");
516 static_assert(IsSame
<AddLvalueReference
<struct S1
&&>::Type
, struct S1
&>::value
,
517 "not reference-collapsing struct S1&& & to struct S1& correctly");
519 static_assert(IsSame
<AddRvalueReference
<int>::Type
, int&&>::value
,
520 "not adding && to int correctly");
522 IsSame
<AddRvalueReference
<volatile int&>::Type
, volatile int&>::value
,
523 "not adding && to volatile int& correctly");
524 static_assert(IsSame
<AddRvalueReference
<const int&&>::Type
, const int&&>::value
,
525 "not adding && to volatile int& correctly");
526 static_assert(IsSame
<AddRvalueReference
<void*>::Type
, void*&&>::value
,
527 "not adding && to void* correctly");
528 static_assert(IsSame
<AddRvalueReference
<void>::Type
, void>::value
,
529 "void shouldn't be transformed by AddRvalueReference");
530 static_assert(IsSame
<AddRvalueReference
<struct S1
&>::Type
, struct S1
&>::value
,
531 "not reference-collapsing struct S1& && to struct S1& correctly");
533 struct TestWithDefaultConstructor
{
534 int foo() const { return 0; }
536 struct TestWithNoDefaultConstructor
{
537 explicit TestWithNoDefaultConstructor(int) {}
538 int foo() const { return 1; }
541 static_assert(IsSame
<decltype(TestWithDefaultConstructor().foo()), int>::value
,
542 "decltype should work using a struct with a default constructor");
544 IsSame
<decltype(DeclVal
<TestWithDefaultConstructor
>().foo()), int>::value
,
545 "decltype should work using a DeclVal'd struct with a default constructor");
547 IsSame
<decltype(DeclVal
<TestWithNoDefaultConstructor
>().foo()), int>::value
,
548 "decltype should work using a DeclVal'd struct without a default "
552 IsSame
<MakeSigned
<const unsigned char>::Type
, const signed char>::value
,
553 "const unsigned char won't signify correctly");
554 static_assert(IsSame
<MakeSigned
<volatile unsigned short>::Type
,
555 volatile signed short>::value
,
556 "volatile unsigned short won't signify correctly");
557 static_assert(IsSame
<MakeSigned
<const volatile unsigned int>::Type
,
558 const volatile signed int>::value
,
559 "const volatile unsigned int won't signify correctly");
560 static_assert(IsSame
<MakeSigned
<unsigned long>::Type
, signed long>::value
,
561 "unsigned long won't signify correctly");
563 IsSame
<MakeSigned
<const signed char>::Type
, const signed char>::value
,
564 "const signed char won't signify correctly");
566 static_assert(IsSame
<MakeSigned
<volatile signed short>::Type
,
567 volatile signed short>::value
,
568 "volatile signed short won't signify correctly");
569 static_assert(IsSame
<MakeSigned
<const volatile signed int>::Type
,
570 const volatile signed int>::value
,
571 "const volatile signed int won't signify correctly");
572 static_assert(IsSame
<MakeSigned
<signed long>::Type
, signed long>::value
,
573 "signed long won't signify correctly");
575 static_assert(IsSame
<MakeSigned
<char>::Type
, signed char>::value
,
576 "char won't signify correctly");
578 IsSame
<MakeSigned
<volatile char>::Type
, volatile signed char>::value
,
579 "volatile char won't signify correctly");
580 static_assert(IsSame
<MakeSigned
<const char>::Type
, const signed char>::value
,
581 "const char won't signify correctly");
584 IsSame
<MakeUnsigned
<const signed char>::Type
, const unsigned char>::value
,
585 "const signed char won't unsignify correctly");
586 static_assert(IsSame
<MakeUnsigned
<volatile signed short>::Type
,
587 volatile unsigned short>::value
,
588 "volatile signed short won't unsignify correctly");
589 static_assert(IsSame
<MakeUnsigned
<const volatile signed int>::Type
,
590 const volatile unsigned int>::value
,
591 "const volatile signed int won't unsignify correctly");
592 static_assert(IsSame
<MakeUnsigned
<signed long>::Type
, unsigned long>::value
,
593 "signed long won't unsignify correctly");
596 IsSame
<MakeUnsigned
<const unsigned char>::Type
, const unsigned char>::value
,
597 "const unsigned char won't unsignify correctly");
599 static_assert(IsSame
<MakeUnsigned
<volatile unsigned short>::Type
,
600 volatile unsigned short>::value
,
601 "volatile unsigned short won't unsignify correctly");
602 static_assert(IsSame
<MakeUnsigned
<const volatile unsigned int>::Type
,
603 const volatile unsigned int>::value
,
604 "const volatile unsigned int won't unsignify correctly");
605 static_assert(IsSame
<MakeUnsigned
<unsigned long>::Type
, unsigned long>::value
,
606 "signed long won't unsignify correctly");
608 static_assert(IsSame
<MakeUnsigned
<char>::Type
, unsigned char>::value
,
609 "char won't unsignify correctly");
611 IsSame
<MakeUnsigned
<volatile char>::Type
, volatile unsigned char>::value
,
612 "volatile char won't unsignify correctly");
614 IsSame
<MakeUnsigned
<const char>::Type
, const unsigned char>::value
,
615 "const char won't unsignify correctly");
617 static_assert(IsSame
<RemoveExtent
<int>::Type
, int>::value
,
618 "removing extent from non-array must return the non-array");
620 IsSame
<RemoveExtent
<const int[]>::Type
, const int>::value
,
621 "removing extent from unknown-bound array must return element type");
623 IsSame
<RemoveExtent
<volatile int[5]>::Type
, volatile int>::value
,
624 "removing extent from known-bound array must return element type");
626 IsSame
<RemoveExtent
<long[][17]>::Type
, long[17]>::value
,
627 "removing extent from multidimensional array must return element type");
629 struct TestRemovePointer
{
633 static_assert(IsSame
<RemovePointer
<int>::Type
, int>::value
,
634 "removing pointer from int must return int");
635 static_assert(IsSame
<RemovePointer
<int*>::Type
, int>::value
,
636 "removing pointer from int* must return int");
637 static_assert(IsSame
<RemovePointer
<int* const>::Type
, int>::value
,
638 "removing pointer from int* const must return int");
639 static_assert(IsSame
<RemovePointer
<int* volatile>::Type
, int>::value
,
640 "removing pointer from int* volatile must return int");
641 static_assert(IsSame
<RemovePointer
<const long*>::Type
, const long>::value
,
642 "removing pointer from const long* must return const long");
643 static_assert(IsSame
<RemovePointer
<void* const>::Type
, void>::value
,
644 "removing pointer from void* const must return void");
645 static_assert(IsSame
<RemovePointer
<void (TestRemovePointer::*)()>::Type
,
646 void (TestRemovePointer::*)()>::value
,
647 "removing pointer from void (S::*)() must return void (S::*)()");
648 static_assert(IsSame
<RemovePointer
<void (*)()>::Type
, void()>::value
,
649 "removing pointer from void (*)() must return void()");
650 static_assert(IsSame
<RemovePointer
<bool TestRemovePointer::*>::Type
,
651 bool TestRemovePointer::*>::value
,
652 "removing pointer from bool S::* must return bool S::*");
654 static_assert(IsSame
<AddPointer
<int>::Type
, int*>::value
,
655 "adding pointer to int must return int*");
656 static_assert(IsSame
<AddPointer
<int*>::Type
, int**>::value
,
657 "adding pointer to int* must return int**");
658 static_assert(IsSame
<AddPointer
<int&>::Type
, int*>::value
,
659 "adding pointer to int& must return int*");
660 static_assert(IsSame
<AddPointer
<int* const>::Type
, int* const*>::value
,
661 "adding pointer to int* const must return int* const*");
662 static_assert(IsSame
<AddPointer
<int* volatile>::Type
, int* volatile*>::value
,
663 "adding pointer to int* volatile must return int* volatile*");
665 static_assert(IsSame
<Decay
<int>::Type
, int>::value
,
666 "decaying int must return int");
667 static_assert(IsSame
<Decay
<int*>::Type
, int*>::value
,
668 "decaying int* must return int*");
669 static_assert(IsSame
<Decay
<int* const>::Type
, int*>::value
,
670 "decaying int* const must return int*");
671 static_assert(IsSame
<Decay
<int* volatile>::Type
, int*>::value
,
672 "decaying int* volatile must return int*");
673 static_assert(IsSame
<Decay
<int&>::Type
, int>::value
,
674 "decaying int& must return int");
675 static_assert(IsSame
<Decay
<const int&>::Type
, int>::value
,
676 "decaying const int& must return int");
677 static_assert(IsSame
<Decay
<int&&>::Type
, int>::value
,
678 "decaying int&& must return int");
679 static_assert(IsSame
<Decay
<int[1]>::Type
, int*>::value
,
680 "decaying int[1] must return int*");
681 static_assert(IsSame
<Decay
<void(int)>::Type
, void (*)(int)>::value
,
682 "decaying void(int) must return void(*)(int)");
685 * Android's broken [u]intptr_t inttype macros are broken because its PRI*PTR
686 * macros are defined as "ld", but sizeof(long) is 8 and sizeof(intptr_t)
687 * is 4 on 32-bit Android. We redefine Android's PRI*PTR macros in
688 * IntegerPrintfMacros.h and assert here that our new definitions match the
689 * actual type sizes seen at compile time.
691 #if defined(ANDROID) && !defined(__LP64__)
692 static_assert(mozilla::IsSame
<int, intptr_t>::value
,
693 "emulated PRI[di]PTR definitions will be wrong");
694 static_assert(mozilla::IsSame
<unsigned int, uintptr_t>::value
,
695 "emulated PRI[ouxX]PTR definitions will be wrong");
699 CPlusPlus11IsBaseOf::StandardIsBaseOfTests();