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 -verify %s 4 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -verify %s 5 // RUN: %clang_cc1 -std=c++20 -fcxx-exceptions -verify %s 6 // RUN: %clang_cc1 -std=c++23 -fcxx-exceptions -verify %s 7 // RUN: %clang_cc1 -std=c++2c -fcxx-exceptions -verify %s 8 9 // 10 // RUN: %clang_cc1 -std=c++17 -fcxx-exceptions -DCONCEPTS_TS=1 -verify %s 11 // RUN: %clang_cc1 -std=c++14 -fno-rtti -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS 12 // RUN: %clang_cc1 -std=c++14 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify %s 13 // RUN: %clang_cc1 -std=c++2a -fno-char8_t -DNO_EXCEPTIONS -DNO_CHAR8_T -verify %s 14 15 // expected-no-diagnostics 16 17 // FIXME using `defined` in a macro has undefined behavior. 18 #if __cplusplus < 201103L 19 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98) 20 #elif __cplusplus < 201402L 21 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11) 22 #elif __cplusplus < 201703L 23 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14) 24 #elif __cplusplus < 202002L 25 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx17 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx17) 26 #elif __cplusplus < 202302L 27 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx20 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx20) 28 #elif __cplusplus == 202302L 29 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx23 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx23) 30 #else 31 #define check(macro, cxx98, cxx11, cxx14, cxx17, cxx20, cxx23, cxx26) (cxx26 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx26) 32 #endif 33 34 // --- C++26 features --- 35 36 #if check(variadic_friend, 202403, 202403, 202403, 202403, 202403, 202403, 202403) 37 #error "wrong value for __cpp_variadic_friend" 38 #endif 39 40 #if check(deleted_function, 202403, 202403, 202403, 202403, 202403, 202403, 202403) 41 #error "wrong value for __cpp_deleted_function" 42 #endif 43 44 #if check(pack_indexing, 202311, 202311, 202311, 202311, 202311, 202311, 202311) 45 #error "wrong value for __cpp_pack_indexing" 46 #endif 47 48 #if check(placeholder_variables, 202306, 202306, 202306, 202306, 202306, 202306, 202306) 49 #error "wrong value for __cpp_placeholder_variables" 50 #endif 51 52 // --- C++23 features --- 53 54 #if check(auto_cast, 0, 0, 0, 0, 0, 202110, 202110) 55 #error "wrong value for __cpp_auto_cast" 56 #endif 57 58 59 #if check(implicit_move, 0, 0, 0, 0, 0, 202207, 202207) 60 #error "wrong value for __cpp_implicit_move" 61 #endif 62 63 #if check(size_t_suffix, 0, 0, 0, 0, 0, 202011, 202011) 64 #error "wrong value for __cpp_size_t_suffix" 65 #endif 66 67 #if check(if_consteval, 0, 0, 0, 0, 0, 202106, 202106) 68 #error "wrong value for __cpp_if_consteval" 69 #endif 70 71 #if check(multidimensional_subscript, 0, 0, 0, 0, 0, 202211, 202211) 72 #error "wrong value for __cpp_multidimensional_subscript" 73 #endif 74 75 #if check(static_call_operator, 0, 202207, 202207, 202207, 202207, 202207, 202207) 76 #error "wrong value for __cpp_static_call_operator" 77 #endif 78 79 #if check(named_character_escapes, 202207, 202207, 202207, 202207, 202207, 202207, 202207) 80 #error "wrong value for __cpp_named_character_escapes" 81 #endif 82 83 #if check(explicit_this_parameter, 0, 0, 0, 0, 0, 202110L, 202110L) 84 #error "wrong value for __cpp_explicit_this_parameter" 85 #endif 86 87 // --- C++20 features --- 88 89 #if check(aggregate_paren_init, 0, 0, 0, 0, 201902, 201902, 201902) 90 #error "wrong value for __cpp_aggregate_paren_init" 91 #endif 92 93 #if defined(CHAR8_T) ? check(char8_t, 202207, 202207, 202207, 202207, 202207, 202207, 202207) : \ 94 defined(NO_CHAR8_T) ? check(char8_t, 0, 0, 0, 0, 0, 0, 0) : \ 95 check(char8_t, 0, 0, 0, 0, 202207, 202207, 202207) 96 #error "wrong value for __cpp_char8_t" 97 #endif 98 99 #if check(concepts, 0, 0, 0, 0, 202002, 202002, 202002) 100 #error "wrong value for __cpp_concepts" 101 #endif 102 103 #if check(conditional_explicit, 0, 0, 0, 0, 201806, 201806, 201806) 104 #error "wrong value for __cpp_conditional_explicit" 105 #endif 106 107 #if check(consteval, 0, 0, 0, 0, 202211, 202211, 202211) 108 #error "wrong value for __cpp_consteval" 109 #endif 110 111 // constexpr checked below 112 113 #if check(constexpr_dynamic_alloc, 0, 0, 0, 0, 201907, 201907, 201907) 114 #error "wrong value for __cpp_constexpr_dynamic_alloc" 115 #endif 116 117 #if check(constexpr_in_decltype, 0, 201711, 201711, 201711, 201711, 201711, 201711) 118 #error "wrong value for __cpp_constexpr_in_decltype" 119 #endif 120 121 #if check(constinit, 0, 0, 0, 0, 201907, 201907, 201907) 122 #error "wrong value for __cpp_constinit" 123 #endif 124 125 // deduction_guides checked below 126 127 #if check(designated_initializers, 0, 0, 0, 0, 201707, 201707, 201707) 128 #error "wrong value for __cpp_designated_initializers" 129 #endif 130 131 // generic_lambdas checked below 132 133 #if check(impl_destroying_delete, 201806, 201806, 201806, 201806, 201806, 201806, 201806) 134 #error "wrong value for __cpp_impl_destroying_delete" 135 #endif 136 137 #if check(impl_three_way_comparison, 0, 0, 0, 0, 201907, 201907, 201907) 138 #error "wrong value for __cpp_impl_three_way_comparison" 139 #endif 140 141 #if check(impl_coroutine, 0, 0, 0, 0, 201902L, 201902L, 201902L) 142 #error "wrong value for __cpp_impl_coroutine" 143 #endif 144 145 // init_captures checked below 146 147 #if check(modules, 0, 0, 0, 0, 0, 0, 0) 148 // FIXME: 201907 in C++20 149 #error "wrong value for __cpp_modules" 150 #endif 151 152 #if check(using_enum, 0, 0, 0, 0, 201907, 201907, 201907) 153 #error "wrong value for __cpp_using_enum" 154 #endif 155 156 // --- C++17 features --- 157 158 #if check(hex_float, 0, 0, 0, 201603, 201603, 201603, 201603) 159 #error "wrong value for __cpp_hex_float" 160 #endif 161 162 #if check(inline_variables, 0, 0, 0, 201606, 201606, 201606, 201606) 163 #error "wrong value for __cpp_inline_variables" 164 #endif 165 166 #if check(aligned_new, 0, 0, 0, 201606, 201606, 201606, 201606) 167 #error "wrong value for __cpp_aligned_new" 168 #endif 169 170 #if check(guaranteed_copy_elision, 0, 0, 0, 201606, 201606, 201606, 201606) 171 #error "wrong value for __cpp_guaranteed_copy_elision" 172 #endif 173 174 #if check(noexcept_function_type, 0, 0, 0, 201510, 201510, 201510, 201510) 175 #error "wrong value for __cpp_noexcept_function_type" 176 #endif 177 178 #if check(fold_expressions, 0, 0, 0, 201603, 201603, 201603, 201603) 179 #error "wrong value for __cpp_fold_expressions" 180 #endif 181 182 #if check(capture_star_this, 0, 0, 0, 201603, 201603, 201603, 201603) 183 #error "wrong value for __cpp_capture_star_this" 184 #endif 185 186 // constexpr checked below 187 188 #if check(if_constexpr, 0, 0, 0, 201606, 201606, 201606, 201606) 189 #error "wrong value for __cpp_if_constexpr" 190 #endif 191 192 #if check(deduction_guides, 0, 0, 0, 201703, 201703, 201703, 201703) 193 // FIXME: 201907 in C++20 194 #error "wrong value for __cpp_deduction_guides" 195 #endif 196 197 #if check(nontype_template_parameter_auto, 0, 0, 0, 201606, 201606, 201606, 201606) 198 #error "wrong value for __cpp_nontype_template_parameter_auto" 199 #endif 200 201 // This is the old name (from P0096R4) for 202 // __cpp_nontype_template_parameter_auto 203 #if check(template_auto, 0, 0, 0, 201606, 201606, 201606, 201606) 204 #error "wrong value for __cpp_template_auto" 205 #endif 206 207 #if check(namespace_attributes, 0, 0, 0, 201411, 201411, 201411, 201411) 208 // FIXME: allowed without warning in C++14 and C++11 209 #error "wrong value for __cpp_namespace_attributes" 210 #endif 211 212 #if check(enumerator_attributes, 0, 0, 0, 201411, 201411, 201411, 201411) 213 // FIXME: allowed without warning in C++14 and C++11 214 #error "wrong value for __cpp_enumerator_attributes" 215 #endif 216 217 // This is an old name (from P0096R4), now removed from SD-6. 218 #if check(nested_namespace_definitions, 0, 0, 0, 201411, 201411, 201411, 201411) 219 #error "wrong value for __cpp_nested_namespace_definitions" 220 #endif 221 222 // inheriting_constructors checked below 223 224 #if check(variadic_using, 0, 0, 0, 201611, 201611, 201611, 201611) 225 #error "wrong value for __cpp_variadic_using" 226 #endif 227 228 #if check(aggregate_bases, 0, 0, 0, 201603, 201603, 201603, 201603) 229 #error "wrong value for __cpp_aggregate_bases" 230 #endif 231 232 #if check(structured_bindings, 0, 0, 0, 202403L, 202403L, 202403L, 202403L) 233 #error "wrong value for __cpp_structured_bindings" 234 #endif 235 236 #if check(nontype_template_args, 0, 0, 0, 201411, 201411, 201411, 201411) 237 // FIXME: 201911 in C++20 238 #error "wrong value for __cpp_nontype_template_args" 239 #endif 240 241 #if check(template_template_args, 201611, 201611, 201611, 201611, 201611, 201611, 201611) 242 #error "wrong value for __cpp_template_template_args" 243 #endif 244 245 // --- C++14 features --- 246 247 #if check(binary_literals, 0, 0, 201304, 201304, 201304, 201304, 201304) 248 #error "wrong value for __cpp_binary_literals" 249 #endif 250 251 // (Removed from SD-6.) 252 #if check(digit_separators, 0, 0, 201309, 201309, 201309, 201309, 201309) 253 #error "wrong value for __cpp_digit_separators" 254 #endif 255 256 #if check(init_captures, 0, 0, 201304, 201304, 201803, 201803, 201803) 257 #error "wrong value for __cpp_init_captures" 258 #endif 259 260 #if check(generic_lambdas, 0, 0, 201304, 201304, 201707, 201707, 201707) 261 #error "wrong value for __cpp_generic_lambdas" 262 #endif 263 264 #if check(sized_deallocation, 0, 0, 201309, 201309, 201309, 201309, 201309) 265 #error "wrong value for __cpp_sized_deallocation" 266 #endif 267 268 // constexpr checked below 269 270 #if check(decltype_auto, 0, 0, 201304, 201304, 201304, 201304, 201304) 271 #error "wrong value for __cpp_decltype_auto" 272 #endif 273 274 #if check(return_type_deduction, 0, 0, 201304, 201304, 201304, 201304, 201304) 275 #error "wrong value for __cpp_return_type_deduction" 276 #endif 277 278 #if check(runtime_arrays, 0, 0, 0, 0, 0, 0, 0) 279 #error "wrong value for __cpp_runtime_arrays" 280 #endif 281 282 #if check(aggregate_nsdmi, 0, 0, 201304, 201304, 201304, 201304, 201304) 283 #error "wrong value for __cpp_aggregate_nsdmi" 284 #endif 285 286 #if check(variable_templates, 0, 0, 201304, 201304, 201304, 201304, 201304) 287 #error "wrong value for __cpp_variable_templates" 288 #endif 289 290 // --- C++11 features --- 291 292 #if check(unicode_characters, 0, 200704, 200704, 200704, 200704, 200704, 200704) 293 #error "wrong value for __cpp_unicode_characters" 294 #endif 295 296 #if check(raw_strings, 0, 200710, 200710, 200710, 200710, 200710, 200710) 297 #error "wrong value for __cpp_raw_strings" 298 #endif 299 300 #if check(unicode_literals, 0, 200710, 200710, 200710, 200710, 200710, 200710) 301 #error "wrong value for __cpp_unicode_literals" 302 #endif 303 304 #if check(user_defined_literals, 0, 200809, 200809, 200809, 200809, 200809, 200809) 305 #error "wrong value for __cpp_user_defined_literals" 306 #endif 307 308 #if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0, 0, 0, 0) : \ 309 check(threadsafe_static_init, 200806, 200806, 200806, 200806, 200806, 200806, 200806) 310 #error "wrong value for __cpp_threadsafe_static_init" 311 #endif 312 313 #if check(lambdas, 0, 200907, 200907, 200907, 200907, 200907, 200907) 314 #error "wrong value for __cpp_lambdas" 315 #endif 316 317 #if check(constexpr, 0, 200704, 201304, 201603, 201907, 202211, 202406L) 318 #error "wrong value for __cpp_constexpr" 319 #endif 320 321 #if check(range_based_for, 0, 200907, 200907, 201603, 201603, 202211, 202211) 322 #error "wrong value for __cpp_range_based_for" 323 #endif 324 325 #if check(static_assert, 0, 202306, 202306, 202306, 202306, 202306, 202306) 326 #error "wrong value for __cpp_static_assert" 327 #endif 328 329 #if check(decltype, 0, 200707, 200707, 200707, 200707, 200707, 200707) 330 #error "wrong value for __cpp_decltype" 331 #endif 332 333 #if check(attributes, 0, 200809, 200809, 200809, 200809, 200809, 200809) 334 #error "wrong value for __cpp_attributes" 335 #endif 336 337 #if check(rvalue_references, 0, 200610, 200610, 200610, 200610, 200610, 200610) 338 #error "wrong value for __cpp_rvalue_references" 339 #endif 340 341 #if check(variadic_templates, 0, 200704, 200704, 200704, 200704, 200704, 200704) 342 #error "wrong value for __cpp_variadic_templates" 343 #endif 344 345 #if check(initializer_lists, 0, 200806, 200806, 200806, 200806, 200806, 200806) 346 #error "wrong value for __cpp_initializer_lists" 347 #endif 348 349 #if check(delegating_constructors, 0, 200604, 200604, 200604, 200604, 200604, 200604) 350 #error "wrong value for __cpp_delegating_constructors" 351 #endif 352 353 #if check(nsdmi, 0, 200809, 200809, 200809, 200809, 200809, 200809) 354 #error "wrong value for __cpp_nsdmi" 355 #endif 356 357 #if check(inheriting_constructors, 0, 201511, 201511, 201511, 201511, 201511, 201511) 358 #error "wrong value for __cpp_inheriting_constructors" 359 #endif 360 361 #if check(ref_qualifiers, 0, 200710, 200710, 200710, 200710, 200710, 200710) 362 #error "wrong value for __cpp_ref_qualifiers" 363 #endif 364 365 #if check(alias_templates, 0, 200704, 200704, 200704, 200704, 200704, 200704) 366 #error "wrong value for __cpp_alias_templates" 367 #endif 368 369 // --- C++98 features --- 370 371 #if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0, 0, 0, 0 ) \ 372 : check(rtti, 199711, 199711, 199711, 199711, 199711, 199711, 199711) 373 #error "wrong value for __cpp_rtti" 374 #endif 375 376 #if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0, 0, 0, 0) \ 377 : check(exceptions, 199711, 199711, 199711, 199711, 199711, 199711, 199711) 378 #error "wrong value for __cpp_exceptions" 379 #endif 380