1 // RUN: %clang_cc1 -std=c++98 -fcxx-exceptions -verify %s 2 // RUN: %clang_cc1 -std=c++11 -fcxx-exceptions -verify %s 3 // RUN: %clang_cc1 -std=c++14 -fcxx-exceptions -fsized-deallocation -verify %s 4 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -verify %s 5 // RUN: %clang_cc1 -std=c++2a -fcxx-exceptions -fsized-deallocation -verify %s 6 // 7 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -frelaxed-template-template-args -DRELAXED_TEMPLATE_TEMPLATE_ARGS=1 -verify %s 8 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -fsized-deallocation -fconcepts-ts -DCONCEPTS_TS=1 -verify %s 9 // RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation 10 // RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s 11 // RUN: %clang_cc1 -std=c++14 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify -fsized-deallocation %s 12 // RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify -fsized-deallocation %s 13 14 // expected-no-diagnostics 15 16 // FIXME using `defined` in a macro has undefined behavior. 17 #if __cplusplus < 201103L 18 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98) 19 #elif __cplusplus < 201402L 20 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11) 21 #elif __cplusplus < 201703L 22 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14) 23 #elif __cplusplus <= 201703L 24 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17) 25 #else 26 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20) (cxx20 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx20) 27 #endif 28 29 // --- C++20 features --- 30 31 #if defined(CHAR8_T) ? check(char8_t, 201811, 201811, 201811, 201811, 201811) : \ 32 defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0) : \ 33 check(char8_t, 0, 0, 0, 0, 201811) 34 #error "wrong value for __cpp_char8_t" 35 #endif 36 37 #if check(constinit, 0, 0, 0, 0, 201907) 38 #error "wrong value for __cpp_constinit" 39 #endif 40 41 #if check(impl_destroying_delete, 201806, 201806, 201806, 201806, 201806) 42 #error "wrong value for __cpp_impl_destroying_delete" 43 #endif 44 45 // --- C++17 features --- 46 47 #if check(hex_float, 0, 0, 0, 201603, 201603) 48 #error "wrong value for __cpp_hex_float" 49 #endif 50 51 #if check(inline_variables, 0, 0, 0, 201606, 201606) 52 #error "wrong value for __cpp_inline_variables" 53 #endif 54 55 #if check(aligned_new, 0, 0, 0, 201606, 201606) 56 #error "wrong value for __cpp_aligned_new" 57 #endif 58 59 #if check(guaranteed_copy_elision, 0, 0, 0, 201606, 201606) 60 #error "wrong value for __cpp_guaranteed_copy_elision" 61 #endif 62 63 #if check(noexcept_function_type, 0, 0, 0, 201510, 201510) 64 #error "wrong value for __cpp_noexcept_function_type" 65 #endif 66 67 #if check(fold_expressions, 0, 0, 0, 201603, 201603) 68 #error "wrong value for __cpp_fold_expressions" 69 #endif 70 71 #if check(capture_star_this, 0, 0, 0, 201603, 201603) 72 #error "wrong value for __cpp_capture_star_this" 73 #endif 74 75 // constexpr checked below 76 77 #if check(if_constexpr, 0, 0, 0, 201606, 201606) 78 #error "wrong value for __cpp_if_constexpr" 79 #endif 80 81 // range_based_for checked below 82 83 // static_assert checked below 84 85 #if check(deduction_guides, 0, 0, 0, 201703, 201703) 86 #error "wrong value for __cpp_deduction_guides" 87 #endif 88 89 #if check(nontype_template_parameter_auto, 0, 0, 0, 201606, 201606) 90 #error "wrong value for __cpp_nontype_template_parameter_auto" 91 #endif 92 93 // This is the old name (from P0096R4) for 94 // __cpp_nontype_template_parameter_auto 95 #if check(template_auto, 0, 0, 0, 201606, 201606) 96 #error "wrong value for __cpp_template_auto" 97 #endif 98 99 #if check(namespace_attributes, 0, 0, 0, 201411, 201411) 100 // FIXME: allowed without warning in C++14 and C++11 101 #error "wrong value for __cpp_namespace_attributes" 102 #endif 103 104 #if check(enumerator_attributes, 0, 0, 0, 201411, 201411) 105 // FIXME: allowed without warning in C++14 and C++11 106 #error "wrong value for __cpp_enumerator_attributes" 107 #endif 108 109 // This is an old name (from P0096R4), now removed from SD-6. 110 #if check(nested_namespace_definitions, 0, 0, 0, 201411, 201411) 111 #error "wrong value for __cpp_nested_namespace_definitions" 112 #endif 113 114 // inheriting_constructors checked below 115 116 #if check(variadic_using, 0, 0, 0, 201611, 201611) 117 #error "wrong value for __cpp_variadic_using" 118 #endif 119 120 #if check(aggregate_bases, 0, 0, 0, 201603, 201603) 121 #error "wrong value for __cpp_aggregate_bases" 122 #endif 123 124 #if check(structured_bindings, 0, 0, 0, 201606, 201606) 125 #error "wrong value for __cpp_structured_bindings" 126 #endif 127 128 #if check(nontype_template_args, 0, 0, 0, 201411, 201411) 129 #error "wrong value for __cpp_nontype_template_args" 130 #endif 131 132 #if defined(RELAXED_TEMPLATE_TEMPLATE_ARGS) \ 133 ? check(template_template_args, 0, 0, 0, 201611, 201611) \ 134 : check(template_template_args, 0, 0, 0, 0, 0) 135 #error "wrong value for __cpp_template_template_args" 136 #endif 137 138 // --- C++14 features --- 139 140 #if check(binary_literals, 0, 0, 201304, 201304, 201304) 141 #error "wrong value for __cpp_binary_literals" 142 #endif 143 144 // (Removed from SD-6.) 145 #if check(digit_separators, 0, 0, 201309, 201309, 201309) 146 #error "wrong value for __cpp_digit_separators" 147 #endif 148 149 #if check(init_captures, 0, 0, 201304, 201304, 201304) 150 #error "wrong value for __cpp_init_captures" 151 #endif 152 153 #if check(generic_lambdas, 0, 0, 201304, 201304, 201304) 154 #error "wrong value for __cpp_generic_lambdas" 155 #endif 156 157 #if check(sized_deallocation, 0, 0, 201309, 201309, 201309) 158 #error "wrong value for __cpp_sized_deallocation" 159 #endif 160 161 // constexpr checked below 162 163 #if check(decltype_auto, 0, 0, 201304, 201304, 201304) 164 #error "wrong value for __cpp_decltype_auto" 165 #endif 166 167 #if check(return_type_deduction, 0, 0, 201304, 201304, 201304) 168 #error "wrong value for __cpp_return_type_deduction" 169 #endif 170 171 #if check(runtime_arrays, 0, 0, 0, 0, 0) 172 #error "wrong value for __cpp_runtime_arrays" 173 #endif 174 175 #if check(aggregate_nsdmi, 0, 0, 201304, 201304, 201304) 176 #error "wrong value for __cpp_aggregate_nsdmi" 177 #endif 178 179 #if check(variable_templates, 0, 0, 201304, 201304, 201304) 180 #error "wrong value for __cpp_variable_templates" 181 #endif 182 183 // --- C++11 features --- 184 185 #if check(unicode_characters, 0, 200704, 200704, 200704, 200704) 186 #error "wrong value for __cpp_unicode_characters" 187 #endif 188 189 #if check(raw_strings, 0, 200710, 200710, 200710, 200710) 190 #error "wrong value for __cpp_raw_strings" 191 #endif 192 193 #if check(unicode_literals, 0, 200710, 200710, 200710, 200710) 194 #error "wrong value for __cpp_unicode_literals" 195 #endif 196 197 #if check(user_defined_literals, 0, 200809, 200809, 200809, 200809) 198 #error "wrong value for __cpp_user_defined_literals" 199 #endif 200 201 #if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0, 0) : \ 202 check(threadsafe_static_init, 200806, 200806, 200806, 200806, 200806) 203 #error "wrong value for __cpp_threadsafe_static_init" 204 #endif 205 206 #if check(lambdas, 0, 200907, 200907, 200907, 200907) 207 #error "wrong value for __cpp_lambdas" 208 #endif 209 210 #if check(constexpr, 0, 200704, 201304, 201603, 201907) 211 #error "wrong value for __cpp_constexpr" 212 #endif 213 214 #if check(range_based_for, 0, 200907, 200907, 201603, 201603) 215 #error "wrong value for __cpp_range_based_for" 216 #endif 217 218 #if check(static_assert, 0, 200410, 200410, 201411, 201411) 219 #error "wrong value for __cpp_static_assert" 220 #endif 221 222 #if check(decltype, 0, 200707, 200707, 200707, 200707) 223 #error "wrong value for __cpp_decltype" 224 #endif 225 226 #if check(attributes, 0, 200809, 200809, 200809, 200809) 227 #error "wrong value for __cpp_attributes" 228 #endif 229 230 #if check(rvalue_references, 0, 200610, 200610, 200610, 200610) 231 #error "wrong value for __cpp_rvalue_references" 232 #endif 233 234 #if check(variadic_templates, 0, 200704, 200704, 200704, 200704) 235 #error "wrong value for __cpp_variadic_templates" 236 #endif 237 238 #if check(initializer_lists, 0, 200806, 200806, 200806, 200806) 239 #error "wrong value for __cpp_initializer_lists" 240 #endif 241 242 #if check(delegating_constructors, 0, 200604, 200604, 200604, 200604) 243 #error "wrong value for __cpp_delegating_constructors" 244 #endif 245 246 #if check(nsdmi, 0, 200809, 200809, 200809, 200809) 247 #error "wrong value for __cpp_nsdmi" 248 #endif 249 250 #if check(inheriting_constructors, 0, 201511, 201511, 201511, 201511) 251 #error "wrong value for __cpp_inheriting_constructors" 252 #endif 253 254 #if check(ref_qualifiers, 0, 200710, 200710, 200710, 200710) 255 #error "wrong value for __cpp_ref_qualifiers" 256 #endif 257 258 #if check(alias_templates, 0, 200704, 200704, 200704, 200704) 259 #error "wrong value for __cpp_alias_templates" 260 #endif 261 262 // --- C++98 features --- 263 264 #if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0, 0) : check(rtti, 199711, 199711, 199711, 199711, 199711) 265 #error "wrong value for __cpp_rtti" 266 #endif 267 268 #if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0, 0) : check(exceptions, 199711, 199711, 199711, 199711, 199711) 269 #error "wrong value for __cpp_exceptions" 270 #endif 271 272 // --- TS features -- 273 274 #if check(experimental_concepts, 0, 0, CONCEPTS_TS, CONCEPTS_TS, CONCEPTS_TS) 275 #error "wrong value for __cpp_experimental_concepts" 276 #endif 277 278 #if defined(COROUTINES) ? check(coroutines, 201703L, 201703L, 201703L, 201703L, 201703L) : check(coroutines, 0, 0, 0, 0, 201703L) 279 #error "wrong value for __cpp_coroutines" 280 #endif 281