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