Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(408)

Side by Side Diff: Source/wtf/TypeTraits.cpp

Issue 802203004: replace COMPILE_ASSERT with static assert in wtf/ (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: final fixups Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/wtf/TypeTraits.h ('k') | Source/wtf/Vector.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010 Google Inc. All rights reserved.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details. 13 * Library General Public License for more details.
14 * 14 *
15 * You should have received a copy of the GNU Library General Public License 15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to 16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA. 18 * Boston, MA 02110-1301, USA.
19 * 19 *
20 */ 20 */
21 21
22 #include "config.h" 22 #include "config.h"
23 #include "TypeTraits.h" 23 #include "TypeTraits.h"
24 24
25 #include "Assertions.h" 25 #include "Assertions.h"
26 #include "Noncopyable.h" 26 #include "Noncopyable.h"
27 27
28 namespace WTF { 28 namespace WTF {
29 29
30 COMPILE_ASSERT(IsInteger<bool>::value, WTF_IsInteger_bool_true); 30 static_assert(IsInteger<bool>::value, "bool should be an integer");
31 COMPILE_ASSERT(IsInteger<char>::value, WTF_IsInteger_char_true); 31 static_assert(IsInteger<char>::value, "char should be an integer");
32 COMPILE_ASSERT(IsInteger<signed char>::value, WTF_IsInteger_signed_char_true); 32 static_assert(IsInteger<signed char>::value, "signed char should be an integer") ;
33 COMPILE_ASSERT(IsInteger<unsigned char>::value, WTF_IsInteger_unsigned_char_true ); 33 static_assert(IsInteger<unsigned char>::value, "unsigned char should be an integ er");
34 COMPILE_ASSERT(IsInteger<short>::value, WTF_IsInteger_short_true); 34 static_assert(IsInteger<short>::value, "short should be an integer");
35 COMPILE_ASSERT(IsInteger<unsigned short>::value, WTF_IsInteger_unsigned_short_tr ue); 35 static_assert(IsInteger<unsigned short>::value, "unsigned short should be an int eger");
36 COMPILE_ASSERT(IsInteger<int>::value, WTF_IsInteger_int_true); 36 static_assert(IsInteger<int>::value, "int should be an integer");
37 COMPILE_ASSERT(IsInteger<unsigned>::value, WTF_IsInteger_unsigned_int_true); 37 static_assert(IsInteger<unsigned>::value, "unsigned int should be an integer");
38 COMPILE_ASSERT(IsInteger<long>::value, WTF_IsInteger_long_true); 38 static_assert(IsInteger<long>::value, "long should be an integer");
39 COMPILE_ASSERT(IsInteger<unsigned long>::value, WTF_IsInteger_unsigned_long_true ); 39 static_assert(IsInteger<unsigned long>::value, "unsigned long should be an integ er");
40 COMPILE_ASSERT(IsInteger<long long>::value, WTF_IsInteger_long_long_true); 40 static_assert(IsInteger<long long>::value, "long long should be an integer");
41 COMPILE_ASSERT(IsInteger<unsigned long long>::value, WTF_IsInteger_unsigned_long _long_true); 41 static_assert(IsInteger<unsigned long long>::value, "unsigned long long should b e an integer");
42 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) 42 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
43 COMPILE_ASSERT(IsInteger<wchar_t>::value, WTF_IsInteger_wchar_t_true); 43 static_assert(IsInteger<wchar_t>::value, "wchar_t should be an integer");
44 #endif 44 #endif
45 COMPILE_ASSERT(!IsInteger<char*>::value, WTF_IsInteger_char_pointer_false); 45 static_assert(!IsInteger<char*>::value, "char pointer should not be an integer") ;
46 COMPILE_ASSERT(!IsInteger<const char*>::value, WTF_IsInteger_const_char_pointer_ false); 46 static_assert(!IsInteger<const char*>::value, "const char pointer should not be an integer");
47 COMPILE_ASSERT(!IsInteger<volatile char*>::value, WTF_IsInteger_volatile_char_po inter_false); 47 static_assert(!IsInteger<volatile char*>::value, "volatile char pointer should n ot be an integer");
48 COMPILE_ASSERT(!IsInteger<double>::value, WTF_IsInteger_double_false); 48 static_assert(!IsInteger<double>::value, "double should not be an integer");
49 COMPILE_ASSERT(!IsInteger<float>::value, WTF_IsInteger_float_false); 49 static_assert(!IsInteger<float>::value, "float should not be an integer");
50 50
51 COMPILE_ASSERT(IsFloatingPoint<float>::value, WTF_IsFloatingPoint_float_true); 51 static_assert(IsFloatingPoint<float>::value, "float should be floating point");
52 COMPILE_ASSERT(IsFloatingPoint<double>::value, WTF_IsFloatingPoint_double_true); 52 static_assert(IsFloatingPoint<double>::value, "double should be floating point") ;
53 COMPILE_ASSERT(IsFloatingPoint<long double>::value, WTF_IsFloatingPoint_long_dou ble_true); 53 static_assert(IsFloatingPoint<long double>::value, "long double should be floati ng point");
54 COMPILE_ASSERT(!IsFloatingPoint<int>::value, WTF_IsFloatingPoint_int_false); 54 static_assert(!IsFloatingPoint<int>::value, "int should not be floating point");
55 55
56 COMPILE_ASSERT(IsPointer<void*>::value, WTF_IsPointer_void_star_true); 56 static_assert(IsPointer<void*>::value, "void* should be a pointer");
57 COMPILE_ASSERT(IsPointer<char*>::value, WTF_IsPointer_char_star_true); 57 static_assert(IsPointer<char*>::value, "char* should be a pointer");
58 COMPILE_ASSERT(IsPointer<const char*>::value, WTF_IsPointer_const_char_star_true ); 58 static_assert(IsPointer<const char*>::value, "const char* should be a pointer");
59 COMPILE_ASSERT(!IsPointer<char>::value, WTF_IsPointer_char_false); 59 static_assert(!IsPointer<char>::value, "char should not be a pointer");
60 COMPILE_ASSERT(!IsPointer<int>::value, WTF_IsPointer_int_false); 60 static_assert(!IsPointer<int>::value, "int should not be a pointer");
61 COMPILE_ASSERT(!IsPointer<long>::value, WTF_IsPointer_long_false); 61 static_assert(!IsPointer<long>::value, "long should not be a pointer");
62 62
63 enum TestEnum { TestEnumValue }; 63 enum TestEnum { TestEnumValue };
64 COMPILE_ASSERT(IsEnum<TestEnum>::value, WTF_IsEnum_enum_true); 64 static_assert(IsEnum<TestEnum>::value, "enum should be an enumerated type");
65 COMPILE_ASSERT(!IsEnum<int>::value, WTF_IsEnum_int_false); 65 static_assert(!IsEnum<int>::value, "int should not be an enumerated type");
66 COMPILE_ASSERT(!IsEnum<TestEnum*>::value, WTF_IsEnum_enum_star_false); 66 static_assert(!IsEnum<TestEnum*>::value, "enum* should not be an enumerated type ");
67 67
68 COMPILE_ASSERT(IsScalar<TestEnum>::value, WTF_IsScalar_enum_true); 68 static_assert(IsScalar<TestEnum>::value, "enum should be scalar");
69 COMPILE_ASSERT(IsScalar<int>::value, WTF_IsScalar_int_true); 69 static_assert(IsScalar<int>::value, "int should be scalar");
70 COMPILE_ASSERT(IsScalar<TestEnum*>::value, WTF_IsScalar_enum_star_true); 70 static_assert(IsScalar<TestEnum*>::value, "enum* should be scalar");
71 COMPILE_ASSERT(IsScalar<double>::value, WTF_IsScalar_double_true); 71 static_assert(IsScalar<double>::value, "double should be scalar");
72 72
73 COMPILE_ASSERT(IsPod<bool>::value, WTF_IsPod_bool_true); 73 static_assert(IsPod<bool>::value, "bool should be a POD");
74 COMPILE_ASSERT(IsPod<char>::value, WTF_IsPod_char_true); 74 static_assert(IsPod<char>::value, "char should be a POD");
75 COMPILE_ASSERT(IsPod<signed char>::value, WTF_IsPod_signed_char_true); 75 static_assert(IsPod<signed char>::value, "signed char should be a POD");
76 COMPILE_ASSERT(IsPod<unsigned char>::value, WTF_IsPod_unsigned_char_true); 76 static_assert(IsPod<unsigned char>::value, "unsigned char should be a POD");
77 COMPILE_ASSERT(IsPod<short>::value, WTF_IsPod_short_true); 77 static_assert(IsPod<short>::value, "short should be a POD");
78 COMPILE_ASSERT(IsPod<unsigned short>::value, WTF_IsPod_unsigned_short_true); 78 static_assert(IsPod<unsigned short>::value, "unsigned short should be a POD");
79 COMPILE_ASSERT(IsPod<int>::value, WTF_IsPod_int_true); 79 static_assert(IsPod<int>::value, "int should be a POD");
80 COMPILE_ASSERT(IsPod<unsigned>::value, WTF_IsPod_unsigned_int_true); 80 static_assert(IsPod<unsigned>::value, "unsigned int should be a POD");
81 COMPILE_ASSERT(IsPod<long>::value, WTF_IsPod_long_true); 81 static_assert(IsPod<long>::value, "long should be a POD");
82 COMPILE_ASSERT(IsPod<unsigned long>::value, WTF_IsPod_unsigned_long_true); 82 static_assert(IsPod<unsigned long>::value, "unsigned long should be a POD");
83 COMPILE_ASSERT(IsPod<long long>::value, WTF_IsPod_long_long_true); 83 static_assert(IsPod<long long>::value, "long long should be a POD");
84 COMPILE_ASSERT(IsPod<unsigned long long>::value, WTF_IsPod_unsigned_long_long_tr ue); 84 static_assert(IsPod<unsigned long long>::value, "unsigned long long should be a POD");
85 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) 85 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
86 COMPILE_ASSERT(IsPod<wchar_t>::value, WTF_IsPod_wchar_t_true); 86 static_assert(IsPod<wchar_t>::value, "wchar_t should be a POD");
87 #endif 87 #endif
88 COMPILE_ASSERT(IsPod<char*>::value, WTF_IsPod_char_pointer_true); 88 static_assert(IsPod<char*>::value, "char* should be a POD");
89 COMPILE_ASSERT(IsPod<const char*>::value, WTF_IsPod_const_char_pointer_true); 89 static_assert(IsPod<const char*>::value, "const char* should be a POD");
90 COMPILE_ASSERT(IsPod<volatile char*>::value, WTF_IsPod_volatile_char_pointer_tru e); 90 static_assert(IsPod<volatile char*>::value, "volatile char* should be a POD");
91 COMPILE_ASSERT(IsPod<double>::value, WTF_IsPod_double_true); 91 static_assert(IsPod<double>::value, "double should be a POD");
92 COMPILE_ASSERT(IsPod<long double>::value, WTF_IsPod_long_double_true); 92 static_assert(IsPod<long double>::value, "long double should be a POD");
93 COMPILE_ASSERT(IsPod<float>::value, WTF_IsPod_float_true); 93 static_assert(IsPod<float>::value, "float should be a POD");
94 struct VirtualClass { 94 struct VirtualClass {
95 virtual void A() { } 95 virtual void A() { }
96 }; 96 };
97 COMPILE_ASSERT(!IsTriviallyMoveAssignable<VirtualClass>::value, WTF_IsTriviallyM oveAssignable_VirtualClass_false); 97 static_assert(!IsTriviallyMoveAssignable<VirtualClass>::value, "VirtualClass sho uld not be trivially move assignable");
98 COMPILE_ASSERT(!IsScalar<VirtualClass>::value, WTF_IsScalar_class_false); 98 static_assert(!IsScalar<VirtualClass>::value, "classes should not be scalar");
99 COMPILE_ASSERT(IsScalar<VirtualClass*>::value, WTF_IsScalar_class_ptr_true); 99 static_assert(IsScalar<VirtualClass*>::value, "pointers to classes should be sca lar");
100 100
101 struct DestructorClass { 101 struct DestructorClass {
102 ~DestructorClass() { } 102 ~DestructorClass() { }
103 }; 103 };
104 COMPILE_ASSERT(IsTriviallyMoveAssignable<DestructorClass>::value, WTF_IsTriviall yMoveAssignable_DestructorClass_true); 104 static_assert(IsTriviallyMoveAssignable<DestructorClass>::value, "DestructorClas s should be trivially move assignable");
105 COMPILE_ASSERT(IsTriviallyCopyAssignable<DestructorClass>::value, WTF_IsTriviall yCopyAssignable_DestructorClass_true); 105 static_assert(IsTriviallyCopyAssignable<DestructorClass>::value, "DestructorClas s should be trivially copy assignable");
106 COMPILE_ASSERT(IsTriviallyDefaultConstructible<DestructorClass>::value, WTF_IsTr iviallyDefaultConstructable_DestructorClass_true); 106 static_assert(IsTriviallyDefaultConstructible<DestructorClass>::value, "Destruct orClass should have a trivial default constructor");
107 107
108 struct MixedPrivate { 108 struct MixedPrivate {
109 int M2() { return m2; } 109 int M2() { return m2; }
110 int m1; 110 int m1;
111 private: 111 private:
112 int m2; 112 int m2;
113 }; 113 };
114 COMPILE_ASSERT(IsTriviallyMoveAssignable<MixedPrivate>::value, WTF_IsTriviallyMo veAssignable_MixedPrivate_true); 114 static_assert(IsTriviallyMoveAssignable<MixedPrivate>::value, "MixedPrivate shou ld be trivially move assignable");
115 COMPILE_ASSERT(IsTriviallyCopyAssignable<MixedPrivate>::value, WTF_IsTriviallyCo pyAssignable_MixedPrivate_true); 115 static_assert(IsTriviallyCopyAssignable<MixedPrivate>::value, "MixedPrivate shou ld be trivially copy assignable");
116 COMPILE_ASSERT(IsTriviallyDefaultConstructible<MixedPrivate>::value, WTF_IsTrivi allyDefaultConstructable_MixedPrivate_true); 116 static_assert(IsTriviallyDefaultConstructible<MixedPrivate>::value, "MixedPrivat e should have a trivial default constructor");
117 struct JustPrivate { 117 struct JustPrivate {
118 int M2() { return m2; } 118 int M2() { return m2; }
119 private: 119 private:
120 int m2; 120 int m2;
121 }; 121 };
122 COMPILE_ASSERT(IsTriviallyMoveAssignable<JustPrivate>::value, WTF_IsTriviallyMov eAssignable_JustPrivate_true); 122 static_assert(IsTriviallyMoveAssignable<JustPrivate>::value, "JustPrivate should be trivially move assignable");
123 COMPILE_ASSERT(IsTriviallyCopyAssignable<JustPrivate>::value, WTF_IsTriviallyCop yAssignable_JustPrivate_true); 123 static_assert(IsTriviallyCopyAssignable<JustPrivate>::value, "JustPrivate should be trivially copy assignable");
124 COMPILE_ASSERT(IsTriviallyDefaultConstructible<JustPrivate>::value, WTF_IsTrivia llyDefaultConstructable_JustPrivate_true); 124 static_assert(IsTriviallyDefaultConstructible<JustPrivate>::value, "JustPrivate should have a trivial default constructor");
125 struct JustPublic { 125 struct JustPublic {
126 int m2; 126 int m2;
127 }; 127 };
128 COMPILE_ASSERT(IsTriviallyMoveAssignable<JustPublic>::value, WTF_IsTriviallyMove Assignable_JustPublic_true); 128 static_assert(IsTriviallyMoveAssignable<JustPublic>::value, "JustPublic should b e trivially move assignable");
129 COMPILE_ASSERT(IsTriviallyCopyAssignable<JustPublic>::value, WTF_IsTriviallyCopy Assignable_JustPublic_true); 129 static_assert(IsTriviallyCopyAssignable<JustPublic>::value, "JustPublic should b e trivially copy assignable");
130 COMPILE_ASSERT(IsTriviallyDefaultConstructible<JustPublic>::value, WTF_IsTrivial lyDefaultConstructable_JustPublic_true); 130 static_assert(IsTriviallyDefaultConstructible<JustPublic>::value, "JustPublic sh ould have a trivial default constructor");
131 struct NestedInherited : public JustPublic, JustPrivate { 131 struct NestedInherited : public JustPublic, JustPrivate {
132 float m3; 132 float m3;
133 }; 133 };
134 COMPILE_ASSERT(IsTriviallyMoveAssignable<NestedInherited>::value, WTF_IsTriviall yMoveAssignable_NestedInherited_true); 134 static_assert(IsTriviallyMoveAssignable<NestedInherited>::value, "NestedInherite d should be trivially move assignable");
135 COMPILE_ASSERT(IsTriviallyCopyAssignable<NestedInherited>::value, WTF_IsTriviall yCopyAssignable_NestedInherited_true); 135 static_assert(IsTriviallyCopyAssignable<NestedInherited>::value, "NestedInherite d should be trivially copy assignable");
136 COMPILE_ASSERT(IsTriviallyDefaultConstructible<NestedInherited>::value, WTF_IsTr iviallyDefaultConstructable_NestedInherited_true); 136 static_assert(IsTriviallyDefaultConstructible<NestedInherited>::value, "NestedIn herited should have a trivial default constructor");
137 struct NestedOwned { 137 struct NestedOwned {
138 JustPublic m1; 138 JustPublic m1;
139 JustPrivate m2; 139 JustPrivate m2;
140 float m3; 140 float m3;
141 }; 141 };
142 142
143 COMPILE_ASSERT(IsTriviallyMoveAssignable<NestedOwned>::value, WTF_IsTriviallyMov eAssignable_NestedOwned_true); 143 static_assert(IsTriviallyMoveAssignable<NestedOwned>::value, "NestedOwned should be trivially move assignable");
144 COMPILE_ASSERT(IsTriviallyCopyAssignable<NestedOwned>::value, WTF_IsTriviallyCop yAssignable_NestedOwned_true); 144 static_assert(IsTriviallyCopyAssignable<NestedOwned>::value, "NestedOwned should be trivially copy assignable");
145 COMPILE_ASSERT(IsTriviallyDefaultConstructible<NestedOwned>::value, WTF_IsTrivia llyDefaultConstructable_NestedOwned_true); 145 static_assert(IsTriviallyDefaultConstructible<NestedOwned>::value, "NestedOwned should have a trivial default constructor");
146 146
147 class NonCopyableClass { 147 class NonCopyableClass {
148 WTF_MAKE_NONCOPYABLE(NonCopyableClass); 148 WTF_MAKE_NONCOPYABLE(NonCopyableClass);
149 }; 149 };
150 #if 0 // Compilers don't get this "right" yet if using = delete. 150 #if 0 // Compilers don't get this "right" yet if using = delete.
151 COMPILE_ASSERT(!IsTriviallyMoveAssignable<NonCopyableClass>::value, WTF_IsTrivia llyMoveAssignable_NonCopyableClass_false); 151 static_assert(!IsTriviallyMoveAssignable<NonCopyableClass>::value, "NonCopyableC lass should not be trivially move assignable");
152 COMPILE_ASSERT(!IsTriviallyCopyAssignable<NonCopyableClass>::value, WTF_IsTrivia llyCopyAssignable_NonCopyableClass_false); 152 static_assert(!IsTriviallyCopyAssignable<NonCopyableClass>::value, "NonCopyableC lass should not be trivially copy assignable");
153 COMPILE_ASSERT(IsTriviallyDefaultConstructible<NonCopyableClass>::value, WTF_IsT riviallyDefaultConstructable_NonCopyableClass_true); 153 static_assert(IsTriviallyDefaultConstructible<NonCopyableClass>::value, "NonCopy ableClass should have a trivial default constructor");
154 #endif // 0 154 #endif // 0
155 155
156 enum IsConvertibleToIntegerCheck { }; 156 enum IsConvertibleToIntegerCheck { };
157 COMPILE_ASSERT(IsConvertibleToInteger<IsConvertibleToIntegerCheck>::value, WTF_I sConvertibleToInteger_enum_true); 157 static_assert(IsConvertibleToInteger<IsConvertibleToIntegerCheck>::value, "enum should be convertible to integer");
158 COMPILE_ASSERT(IsConvertibleToInteger<bool>::value, WTF_IsConvertibleToInteger_b ool_true); 158 static_assert(IsConvertibleToInteger<bool>::value, "bool should be convertible t o integer");
159 COMPILE_ASSERT(IsConvertibleToInteger<char>::value, WTF_IsConvertibleToInteger_c har_true); 159 static_assert(IsConvertibleToInteger<char>::value, "char should be convertible t o integer");
160 COMPILE_ASSERT(IsConvertibleToInteger<signed char>::value, WTF_IsConvertibleToIn teger_signed_char_true); 160 static_assert(IsConvertibleToInteger<signed char>::value, "signed char should be convertible to integer");
161 COMPILE_ASSERT(IsConvertibleToInteger<unsigned char>::value, WTF_IsConvertibleTo Integer_unsigned_char_true); 161 static_assert(IsConvertibleToInteger<unsigned char>::value, "unsigned char shoul d be convertible to integer");
162 COMPILE_ASSERT(IsConvertibleToInteger<short>::value, WTF_IsConvertibleToInteger_ short_true); 162 static_assert(IsConvertibleToInteger<short>::value, "short should be convertible to integer");
163 COMPILE_ASSERT(IsConvertibleToInteger<unsigned short>::value, WTF_IsConvertibleT oInteger_unsigned_short_true); 163 static_assert(IsConvertibleToInteger<unsigned short>::value, "unsigned short sho uld be convertible to integer");
164 COMPILE_ASSERT(IsConvertibleToInteger<int>::value, WTF_IsConvertibleToInteger_in t_true); 164 static_assert(IsConvertibleToInteger<int>::value, "int should be convertible to integer");
165 COMPILE_ASSERT(IsConvertibleToInteger<unsigned>::value, WTF_IsConvertibleToInteg er_unsigned_int_true); 165 static_assert(IsConvertibleToInteger<unsigned>::value, "unsigned int should be c onvertible to integer");
166 COMPILE_ASSERT(IsConvertibleToInteger<long>::value, WTF_IsConvertibleToInteger_l ong_true); 166 static_assert(IsConvertibleToInteger<long>::value, "long should be convertible t o integer");
167 COMPILE_ASSERT(IsConvertibleToInteger<unsigned long>::value, WTF_IsConvertibleTo Integer_unsigned_long_true); 167 static_assert(IsConvertibleToInteger<unsigned long>::value, "unsigned long shoul d be convertible to integer");
168 COMPILE_ASSERT(IsConvertibleToInteger<long long>::value, WTF_IsConvertibleToInte ger_long_long_true); 168 static_assert(IsConvertibleToInteger<long long>::value, "long long should be con vertible to integer");
169 COMPILE_ASSERT(IsConvertibleToInteger<unsigned long long>::value, WTF_IsConverti bleToInteger_unsigned_long_long_true); 169 static_assert(IsConvertibleToInteger<unsigned long long>::value, "unsigned long long should be convertible to integer");
170 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED) 170 #if !COMPILER(MSVC) || defined(_NATIVE_WCHAR_T_DEFINED)
171 COMPILE_ASSERT(IsConvertibleToInteger<wchar_t>::value, WTF_IsConvertibleToIntege r_wchar_t_true); 171 static_assert(IsConvertibleToInteger<wchar_t>::value, "whcar_t should be convert ible to integer");
172 #endif 172 #endif
173 COMPILE_ASSERT(IsConvertibleToInteger<double>::value, WTF_IsConvertibleToInteger _double_true); 173 static_assert(IsConvertibleToInteger<double>::value, "double should be convertib le to integer");
174 COMPILE_ASSERT(IsConvertibleToInteger<long double>::value, WTF_IsConvertibleToIn teger_long_double_true); 174 static_assert(IsConvertibleToInteger<long double>::value, "long double should be convertible to integer");
175 COMPILE_ASSERT(IsConvertibleToInteger<float>::value, WTF_IsConvertibleToInteger_ float_true); 175 static_assert(IsConvertibleToInteger<float>::value, "float should be convertible to integer");
176 COMPILE_ASSERT(!IsConvertibleToInteger<char*>::value, WTF_IsConvertibleToInteger _char_pointer_false); 176 static_assert(!IsConvertibleToInteger<char*>::value, "char* should not be conver tible to integer");
177 COMPILE_ASSERT(!IsConvertibleToInteger<const char*>::value, WTF_IsConvertibleToI nteger_const_char_pointer_false); 177 static_assert(!IsConvertibleToInteger<const char*>::value, "const char* should n ot be convertible to integer");
178 COMPILE_ASSERT(!IsConvertibleToInteger<volatile char*>::value, WTF_IsConvertible ToInteger_volatile_char_pointer_false); 178 static_assert(!IsConvertibleToInteger<volatile char*>::value, "volatile char* sh ould not be convertible to integer");
179 COMPILE_ASSERT(!IsConvertibleToInteger<IsConvertibleToInteger<bool> >::value, WT F_IsConvertibleToInteger_struct_false); 179 static_assert(!IsConvertibleToInteger<IsConvertibleToInteger<bool> >::value, "st ruct should not be convertible to integer");
180 180
181 COMPILE_ASSERT((IsPointerConvertible<int, int>::Value), WTF_IsPointerConvertible _same_type_true); 181 static_assert((IsPointerConvertible<int, int>::Value), "pointers to the same typ e should be convertible");
182 COMPILE_ASSERT((!IsPointerConvertible<int, unsigned>::Value), WTF_IsPointerConve rtible_int_to_unsigned_false); 182 static_assert((!IsPointerConvertible<int, unsigned>::Value), "int pointers shoul d not be convertible to unsigned pointers");
183 COMPILE_ASSERT((IsPointerConvertible<int, const int>::Value), WTF_IsPointerConve rtible_int_to_const_int_true); 183 static_assert((IsPointerConvertible<int, const int>::Value), "int pointers shoul d be convertible to const int pointers");
184 COMPILE_ASSERT((!IsPointerConvertible<const int, int>::Value), WTF_IsPointerConv ertible_const_int_to_int_false); 184 static_assert((!IsPointerConvertible<const int, int>::Value), "const int* should not be convertible to int*");
185 COMPILE_ASSERT((IsPointerConvertible<int, volatile int>::Value), WTF_IsPointerCo nvertible_int_to_volatile_int_true); 185 static_assert((IsPointerConvertible<int, volatile int>::Value), "int* should be convertible to volatile int*");
186 186
187 COMPILE_ASSERT((IsSameType<bool, bool>::value), WTF_IsSameType_bool_true); 187 static_assert((IsSameType<bool, bool>::value), "bool should be the same type as itself");
188 COMPILE_ASSERT((IsSameType<int*, int*>::value), WTF_IsSameType_int_pointer_true) ; 188 static_assert((IsSameType<int*, int*>::value), "int* should be the same type as itself");
189 COMPILE_ASSERT((!IsSameType<int, int*>::value), WTF_IsSameType_int_int_pointer_f alse); 189 static_assert((!IsSameType<int, int*>::value), "int should not be the same type as int*");
190 COMPILE_ASSERT((!IsSameType<bool, const bool>::value), WTF_IsSameType_const_chan ge_false); 190 static_assert((!IsSameType<bool, const bool>::value), "T should not be the same type as const T");
191 COMPILE_ASSERT((!IsSameType<bool, volatile bool>::value), WTF_IsSameType_volatil e_change_false); 191 static_assert((!IsSameType<bool, volatile bool>::value), "T should not be the sa me type as volatile T");
192 192
193 template <typename T> 193 template <typename T>
194 class TestBaseClass { 194 class TestBaseClass {
195 }; 195 };
196 196
197 class TestDerivedClass : public TestBaseClass<int> { 197 class TestDerivedClass : public TestBaseClass<int> {
198 }; 198 };
199 199
200 COMPILE_ASSERT((IsSubclass<TestDerivedClass, TestBaseClass<int> >::value), WTF_T est_IsSubclass_Derived_From_Base); 200 static_assert((IsSubclass<TestDerivedClass, TestBaseClass<int> >::value), "Deriv ed class should be a subclass of its base");
201 COMPILE_ASSERT((!IsSubclass<TestBaseClass<int>, TestDerivedClass>::value), WTF_T est_IsSubclass_Base_From_Derived); 201 static_assert((!IsSubclass<TestBaseClass<int>, TestDerivedClass>::value), "Base class should not be a sublass of a derived class");
202 COMPILE_ASSERT((IsSubclassOfTemplate<TestDerivedClass, TestBaseClass>::value), W TF_Test_IsSubclassOfTemplate_Base_From_Derived); 202 static_assert((IsSubclassOfTemplate<TestDerivedClass, TestBaseClass>::value), "D erived class should be a subclass of template from its base");
203 COMPILE_ASSERT((IsSameType<RemoveTemplate<TestBaseClass<int>, TestBaseClass>::Ty pe, int>::value), WTF_Test_RemoveTemplate); 203 static_assert((IsSameType<RemoveTemplate<TestBaseClass<int>, TestBaseClass>::Typ e, int>::value), "RemoveTemplate should remove the template typename from the ty pe");
204 COMPILE_ASSERT((IsSameType<RemoveTemplate<int, TestBaseClass>::Type, int>::value ), WTF_Test_RemoveTemplate_WithoutTemplate); 204 static_assert((IsSameType<RemoveTemplate<int, TestBaseClass>::Type, int>::value) , "RemoveTemplate should not alter non-template types");
205 COMPILE_ASSERT((IsPointerConvertible<TestDerivedClass, TestBaseClass<int> >::Val ue), WTF_Test_IsPointerConvertible_Derived_To_Base); 205 static_assert((IsPointerConvertible<TestDerivedClass, TestBaseClass<int> >::Valu e), "Derived class pointers should be convertible to base class pointers");
206 COMPILE_ASSERT((!IsPointerConvertible<TestBaseClass<int>, TestDerivedClass>::Val ue), WTF_Test_IsPointerConvertible_Base_To_Derived); 206 static_assert((!IsPointerConvertible<TestBaseClass<int>, TestDerivedClass>::Valu e), "Base class pointers should not be convertible to derived class pointers");
207 207
208 COMPILE_ASSERT((IsSameType<bool, RemoveConst<const bool>::Type>::value), WTF_tes t_RemoveConst_const_bool); 208 static_assert((IsSameType<bool, RemoveConst<const bool>::Type>::value), "RemoveC onst should produce the corresponding non-const type");
209 COMPILE_ASSERT((!IsSameType<bool, RemoveConst<volatile bool>::Type>::value), WTF _test_RemoveConst_volatile_bool); 209 static_assert((!IsSameType<bool, RemoveConst<volatile bool>::Type>::value), "Rem oveConst of volatile types should not remove volatility");
210 210
211 COMPILE_ASSERT((IsSameType<bool, RemoveVolatile<bool>::Type>::value), WTF_test_R emoveVolatile_bool); 211 static_assert((IsSameType<bool, RemoveVolatile<bool>::Type>::value), "RemoveVola tile should not modify the type of non-volatile types");
212 COMPILE_ASSERT((!IsSameType<bool, RemoveVolatile<const bool>::Type>::value), WTF _test_RemoveVolatile_const_bool); 212 static_assert((!IsSameType<bool, RemoveVolatile<const bool>::Type>::value), "Rem oveVolatile should not remove const-ness");
213 COMPILE_ASSERT((IsSameType<bool, RemoveVolatile<volatile bool>::Type>::value), W TF_test_RemoveVolatile_volatile_bool); 213 static_assert((IsSameType<bool, RemoveVolatile<volatile bool>::Type>::value), "R emoveVolatile should produce the equivalent non-volatile type");
214 214
215 COMPILE_ASSERT((IsSameType<bool, RemoveConstVolatile<bool>::Type>::value), WTF_t est_RemoveConstVolatile_bool); 215 static_assert((IsSameType<bool, RemoveConstVolatile<bool>::Type>::value), "Remov eConstVolatile should not modify the type of non-const non-volatile types");
216 COMPILE_ASSERT((IsSameType<bool, RemoveConstVolatile<const bool>::Type>::value), WTF_test_RemoveConstVolatile_const_bool); 216 static_assert((IsSameType<bool, RemoveConstVolatile<const bool>::Type>::value), "RemoveConstVolatile should remove const-ness");
217 COMPILE_ASSERT((IsSameType<bool, RemoveConstVolatile<volatile bool>::Type>::valu e), WTF_test_RemoveConstVolatile_volatile_bool); 217 static_assert((IsSameType<bool, RemoveConstVolatile<volatile bool>::Type>::value ), "RemoveConstVolatile should remove volatility");
218 COMPILE_ASSERT((IsSameType<bool, RemoveConstVolatile<const volatile bool>::Type> ::value), WTF_test_RemoveConstVolatile_const_volatile_bool); 218 static_assert((IsSameType<bool, RemoveConstVolatile<const volatile bool>::Type>: :value), "RemoveConstVolatile should remove both constness and volatility");
219 219
220 COMPILE_ASSERT((IsSameType<int, RemovePointer<int>::Type>::value), WTF_Test_Remo vePointer_int); 220 static_assert((IsSameType<int, RemovePointer<int>::Type>::value), "RemovePointer should not modify non-pointer types");
221 COMPILE_ASSERT((IsSameType<int, RemovePointer<int*>::Type>::value), WTF_Test_Rem ovePointer_int_pointer); 221 static_assert((IsSameType<int, RemovePointer<int*>::Type>::value), "RemovePointe r should produce the corresponding non-pointer type");
222 COMPILE_ASSERT((!IsSameType<int, RemovePointer<int**>::Type>::value), WTF_Test_R emovePointer_int_pointer_pointer); 222 static_assert((!IsSameType<int, RemovePointer<int**>::Type>::value), "RemovePoin ter should only remove one pointer level");
223 223
224 COMPILE_ASSERT((IsSameType<int, RemoveReference<int>::Type>::value), WTF_Test_Re moveReference_int); 224 static_assert((IsSameType<int, RemoveReference<int>::Type>::value), "RemoveRefer ence should not modify non-reference types");
225 COMPILE_ASSERT((IsSameType<int, RemoveReference<int&>::Type>::value), WTF_Test_R emoveReference_int_reference); 225 static_assert((IsSameType<int, RemoveReference<int&>::Type>::value), "RemoveRefe rence should produce the corresponding non-reference type");
226 226
227 227
228 typedef int IntArray[]; 228 typedef int IntArray[];
229 typedef int IntArraySized[4]; 229 typedef int IntArraySized[4];
230 230
231 COMPILE_ASSERT((IsArray<IntArray>::value), WTF_Test_IsArray_int_array); 231 static_assert((IsArray<IntArray>::value), "IsArray should recognize arrays");
232 COMPILE_ASSERT((IsArray<IntArraySized>::value), WTF_Test_IsArray_int_sized_array ); 232 static_assert((IsArray<IntArraySized>::value), "IsArray should recognize sized a rrays");
233 233
234 COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArray>::Type>::value), WTF_Test_ RemoveExtent_int_array); 234 static_assert((IsSameType<int, RemoveExtent<IntArray>::Type>::value), "RemoveExt ent should return the array element type of an array");
235 COMPILE_ASSERT((IsSameType<int, RemoveExtent<IntArraySized>::Type>::value), WTF_ Test_RemoveReference_int_sized_array); 235 static_assert((IsSameType<int, RemoveExtent<IntArraySized>::Type>::value), "Remo veExtent should return the array element type of a sized array");
236 236
237 } // namespace WTF 237 } // namespace WTF
OLDNEW
« no previous file with comments | « Source/wtf/TypeTraits.h ('k') | Source/wtf/Vector.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698