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