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