Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 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++1y -fcxx-exceptions -fsized-deallocation -verify %s |
| 4 | // RUN: %clang_cc1 -std=c++14 -fcxx-exceptions -fsized-deallocation -verify %s |
| 5 | // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fsized-deallocation -verify %s |
| 6 | // RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fsized-deallocation -fconcepts-ts -DCONCEPTS_TS=1 -verify %s |
| 7 | // RUN: %clang_cc1 -fno-rtti -verify %s -DNO_EXCEPTIONS -DNO_RTTI |
| 8 | // RUN: %clang_cc1 -fcoroutines -DNO_EXCEPTIONS -DCOROUTINES -verify %s |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 9 | |
| 10 | // expected-no-diagnostics |
| 11 | |
Nico Weber | b2348f4 | 2016-01-19 15:15:31 +0000 | [diff] [blame] | 12 | // FIXME using `defined` in a macro has undefined behavior. |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 13 | #if __cplusplus < 201103L |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 14 | #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98 |
| 15 | #elif __cplusplus < 201402L |
| 16 | #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11 |
| 17 | #elif __cplusplus < 201406L |
| 18 | #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14 |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 19 | #else |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 20 | #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx1z == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx1z |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 21 | #endif |
| 22 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 23 | // --- C++17 features --- |
| 24 | |
Richard Smith | 38d91d4 | 2016-09-28 20:26:06 +0000 | [diff] [blame] | 25 | #if check(hex_float, 0, 0, 0, 201603) |
| 26 | #error "wrong value for __cpp_hex_float" |
| 27 | #endif |
| 28 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 29 | #if check(noexcept_function_type, 0, 0, 0, 0) |
Richard Smith | 38d91d4 | 2016-09-28 20:26:06 +0000 | [diff] [blame] | 30 | // FIXME: value shuld be 201510 for cxx1z once implemented |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 31 | #error "wrong value for __cpp_noexcept_function_type" |
| 32 | #endif |
| 33 | |
Richard Smith | 38d91d4 | 2016-09-28 20:26:06 +0000 | [diff] [blame] | 34 | #if check(fold_expressions, 0, 0, 0, 201603) |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 35 | #error "wrong value for __cpp_fold_expressions" |
| 36 | #endif |
| 37 | |
Richard Smith | 38d91d4 | 2016-09-28 20:26:06 +0000 | [diff] [blame] | 38 | #if check(capture_star_this, 0, 0, 0, 201603) |
| 39 | #error "wrong value for __cpp_capture_star_this" |
| 40 | #endif |
| 41 | |
| 42 | // FIXME: bump __cpp_constexpr to 201603 for constexpr lambda support |
| 43 | |
| 44 | // range_based_for checked below |
| 45 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 46 | // static_assert checked below |
| 47 | |
| 48 | #if check(namespace_attributes, 0, 0, 0, 201411) |
| 49 | // FIXME: allowed without warning in C++14 and C++11 |
| 50 | #error "wrong value for __cpp_namespace_attributes" |
| 51 | #endif |
| 52 | |
| 53 | #if check(enumerator_attributes, 0, 0, 0, 201411) |
| 54 | // FIXME: allowed without warning in C++14 and C++11 |
| 55 | #error "wrong value for __cpp_enumerator_attributes" |
| 56 | #endif |
| 57 | |
| 58 | #if check(nested_namespace_definitions, 0, 0, 0, 201411) |
| 59 | #error "wrong value for __cpp_nested_namespace_definitions" |
| 60 | #endif |
| 61 | |
Richard Smith | 38d91d4 | 2016-09-28 20:26:06 +0000 | [diff] [blame] | 62 | #if check(aggregate_bases, 0, 0, 0, 201603) |
| 63 | #error "wrong value for __cpp_aggregate_bases" |
| 64 | #endif |
| 65 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 66 | #if check(nontype_template_args, 0, 0, 0, 201411) |
| 67 | #error "wrong value for __cpp_nontype_template_args" |
| 68 | #endif |
| 69 | |
| 70 | // --- C++14 features --- |
| 71 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 72 | #if check(binary_literals, 0, 0, 201304, 201304) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 73 | #error "wrong value for __cpp_binary_literals" |
| 74 | #endif |
| 75 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 76 | // (Removed from SD-6.) |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 77 | #if check(digit_separators, 0, 0, 201309, 201309) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 78 | #error "wrong value for __cpp_digit_separators" |
| 79 | #endif |
| 80 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 81 | #if check(init_captures, 0, 0, 201304, 201304) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 82 | #error "wrong value for __cpp_init_captures" |
| 83 | #endif |
| 84 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 85 | #if check(generic_lambdas, 0, 0, 201304, 201304) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 86 | #error "wrong value for __cpp_generic_lambdas" |
| 87 | #endif |
| 88 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 89 | #if check(sized_deallocation, 0, 0, 201309, 201309) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 90 | #error "wrong value for __cpp_sized_deallocation" |
| 91 | #endif |
| 92 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 93 | // constexpr checked below |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 94 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 95 | #if check(decltype_auto, 0, 0, 201304, 201304) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 96 | #error "wrong value for __cpp_decltype_auto" |
| 97 | #endif |
| 98 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 99 | #if check(return_type_deduction, 0, 0, 201304, 201304) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 100 | #error "wrong value for __cpp_return_type_deduction" |
| 101 | #endif |
| 102 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 103 | #if check(runtime_arrays, 0, 0, 0, 0) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 104 | #error "wrong value for __cpp_runtime_arrays" |
| 105 | #endif |
| 106 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 107 | #if check(aggregate_nsdmi, 0, 0, 201304, 201304) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 108 | #error "wrong value for __cpp_aggregate_nsdmi" |
| 109 | #endif |
| 110 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 111 | #if check(variable_templates, 0, 0, 201304, 201304) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 112 | #error "wrong value for __cpp_variable_templates" |
| 113 | #endif |
| 114 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 115 | // --- C++11 features --- |
| 116 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 117 | #if check(unicode_characters, 0, 200704, 200704, 200704) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 118 | #error "wrong value for __cpp_unicode_characters" |
| 119 | #endif |
| 120 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 121 | #if check(raw_strings, 0, 200710, 200710, 200710) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 122 | #error "wrong value for __cpp_raw_strings" |
| 123 | #endif |
| 124 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 125 | #if check(unicode_literals, 0, 200710, 200710, 200710) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 126 | #error "wrong value for __cpp_unicode_literals" |
| 127 | #endif |
| 128 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 129 | #if check(user_defined_literals, 0, 200809, 200809, 200809) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 130 | #error "wrong value for __cpp_user_defined_literals" |
| 131 | #endif |
| 132 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 133 | #if check(lambdas, 0, 200907, 200907, 200907) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 134 | #error "wrong value for __cpp_lambdas" |
| 135 | #endif |
| 136 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 137 | #if check(constexpr, 0, 200704, 201304, 201304) |
| 138 | #error "wrong value for __cpp_constexpr" |
| 139 | #endif |
| 140 | |
Richard Smith | 38d91d4 | 2016-09-28 20:26:06 +0000 | [diff] [blame] | 141 | #if check(range_based_for, 0, 200907, 200907, 201603) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 142 | #error "wrong value for __cpp_range_based_for" |
| 143 | #endif |
| 144 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 145 | #if check(static_assert, 0, 200410, 200410, 201411) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 146 | #error "wrong value for __cpp_static_assert" |
| 147 | #endif |
| 148 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 149 | #if check(decltype, 0, 200707, 200707, 200707) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 150 | #error "wrong value for __cpp_decltype" |
| 151 | #endif |
| 152 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 153 | #if check(attributes, 0, 200809, 200809, 200809) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 154 | #error "wrong value for __cpp_attributes" |
| 155 | #endif |
| 156 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 157 | #if check(rvalue_references, 0, 200610, 200610, 200610) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 158 | #error "wrong value for __cpp_rvalue_references" |
| 159 | #endif |
| 160 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 161 | #if check(variadic_templates, 0, 200704, 200704, 200704) |
Richard Smith | 91e474f | 2013-11-27 22:58:16 +0000 | [diff] [blame] | 162 | #error "wrong value for __cpp_variadic_templates" |
| 163 | #endif |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 164 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 165 | #if check(initializer_lists, 0, 200806, 200806, 200806) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 166 | #error "wrong value for __cpp_initializer_lists" |
| 167 | #endif |
| 168 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 169 | #if check(delegating_constructors, 0, 200604, 200604, 200604) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 170 | #error "wrong value for __cpp_delegating_constructors" |
| 171 | #endif |
| 172 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 173 | #if check(nsdmi, 0, 200809, 200809, 200809) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 174 | #error "wrong value for __cpp_nsdmi" |
| 175 | #endif |
| 176 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 177 | #if check(inheriting_constructors, 0, 201511, 201511, 201511) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 178 | #error "wrong value for __cpp_inheriting_constructors" |
| 179 | #endif |
| 180 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 181 | #if check(ref_qualifiers, 0, 200710, 200710, 200710) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 182 | #error "wrong value for __cpp_ref_qualifiers" |
| 183 | #endif |
| 184 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 185 | #if check(alias_templates, 0, 200704, 200704, 200704) |
Richard Smith | 38af856 | 2014-11-12 21:16:38 +0000 | [diff] [blame] | 186 | #error "wrong value for __cpp_alias_templates" |
| 187 | #endif |
Faisal Vali | 24d59d1 | 2015-05-22 01:11:10 +0000 | [diff] [blame] | 188 | |
Richard Smith | b02043c | 2016-09-28 19:44:50 +0000 | [diff] [blame] | 189 | // --- C++98 features --- |
| 190 | |
| 191 | #if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0) : check(rtti, 199711, 199711, 199711, 199711) |
| 192 | #error "wrong value for __cpp_rtti" |
| 193 | #endif |
| 194 | |
| 195 | #if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0) : check(exceptions, 199711, 199711, 199711, 199711) |
| 196 | #error "wrong value for __cpp_exceptions" |
| 197 | #endif |
| 198 | |
| 199 | // --- TS features -- |
| 200 | |
JF Bastien | e3c13a8 | 2016-03-22 21:12:48 +0000 | [diff] [blame] | 201 | #if check(experimental_concepts, 0, 0, CONCEPTS_TS, CONCEPTS_TS) |
Faisal Vali | 24d59d1 | 2015-05-22 01:11:10 +0000 | [diff] [blame] | 202 | #error "wrong value for __cpp_experimental_concepts" |
| 203 | #endif |
Richard Smith | 3fa73f3 | 2015-10-22 04:27:47 +0000 | [diff] [blame] | 204 | |
| 205 | #if (COROUTINES && !__cpp_coroutines) || (!COROUTINES && __cpp_coroutines) |
| 206 | #error "wrong value for __cpp_coroutines" |
| 207 | #endif |