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