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