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 -fno-threadsafe-statics -verify %s -DNO_EXCEPTIONS -DNO_RTTI -DNO_THREADSAFE_STATICS -fsized-deallocation
8 // RUN: %clang_cc1 -fcoroutines-ts -DNO_EXCEPTIONS -DCOROUTINES -verify -fsized-deallocation %s
9 // RUN: %clang_cc1 -fchar8_t -DNO_EXCEPTIONS -DCHAR8_T -verify -fsized-deallocation %s
10 
11 // expected-no-diagnostics
12 
13 // FIXME using `defined` in a macro has undefined behavior.
14 #if __cplusplus < 201103L
15 #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx98 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx98
16 #elif __cplusplus < 201402L
17 #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx11 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx11
18 #elif __cplusplus < 201406L
19 #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx14 == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx14
20 #else
21 #define check(macro, cxx98, cxx11, cxx14, cxx1z) cxx1z == 0 ? defined(__cpp_##macro) : __cpp_##macro != cxx1z
22 #endif
23 
24 // --- C++17 features ---
25 
26 #if check(hex_float, 0, 0, 0, 201603)
27 #error "wrong value for __cpp_hex_float"
28 #endif
29 
30 #if check(inline_variables, 0, 0, 0, 201606)
31 #error "wrong value for __cpp_inline_variables"
32 #endif
33 
34 #if check(aligned_new, 0, 0, 0, 201606)
35 #error "wrong value for __cpp_aligned_new"
36 #endif
37 
38 #if check(noexcept_function_type, 0, 0, 0, 201510)
39 #error "wrong value for __cpp_noexcept_function_type"
40 #endif
41 
42 #if check(fold_expressions, 0, 0, 0, 201603)
43 #error "wrong value for __cpp_fold_expressions"
44 #endif
45 
46 #if check(capture_star_this, 0, 0, 0, 201603)
47 #error "wrong value for __cpp_capture_star_this"
48 #endif
49 
50 // constexpr checked below
51 
52 #if check(if_constexpr, 0, 0, 0, 201606)
53 #error "wrong value for __cpp_if_constexpr"
54 #endif
55 
56 // range_based_for checked below
57 
58 // static_assert checked below
59 
60 #if check(deduction_guides, 0, 0, 0, 201611)
61 #error "wrong value for __cpp_deduction_guides"
62 #endif
63 
64 #if check(template_auto, 0, 0, 0, 201606)
65 #error "wrong value for __cpp_template_auto"
66 #endif
67 
68 #if check(namespace_attributes, 0, 0, 0, 201411)
69 // FIXME: allowed without warning in C++14 and C++11
70 #error "wrong value for __cpp_namespace_attributes"
71 #endif
72 
73 #if check(enumerator_attributes, 0, 0, 0, 201411)
74 // FIXME: allowed without warning in C++14 and C++11
75 #error "wrong value for __cpp_enumerator_attributes"
76 #endif
77 
78 #if check(nested_namespace_definitions, 0, 0, 0, 201411)
79 #error "wrong value for __cpp_nested_namespace_definitions"
80 #endif
81 
82 // inheriting_constructors checked below
83 
84 #if check(variadic_using, 0, 0, 0, 201611)
85 #error "wrong value for __cpp_variadic_using"
86 #endif
87 
88 #if check(aggregate_bases, 0, 0, 0, 201603)
89 #error "wrong value for __cpp_aggregate_bases"
90 #endif
91 
92 #if check(structured_bindings, 0, 0, 0, 201606)
93 #error "wrong value for __cpp_structured_bindings"
94 #endif
95 
96 #if check(nontype_template_args, 0, 0, 0, 201411)
97 #error "wrong value for __cpp_nontype_template_args"
98 #endif
99 
100 #if check(template_template_args, 0, 0, 0, 0) // FIXME: should be 201611 when feature is enabled
101 #error "wrong value for __cpp_template_template_args"
102 #endif
103 
104 // --- C++14 features ---
105 
106 #if check(binary_literals, 0, 0, 201304, 201304)
107 #error "wrong value for __cpp_binary_literals"
108 #endif
109 
110 // (Removed from SD-6.)
111 #if check(digit_separators, 0, 0, 201309, 201309)
112 #error "wrong value for __cpp_digit_separators"
113 #endif
114 
115 #if check(init_captures, 0, 0, 201304, 201304)
116 #error "wrong value for __cpp_init_captures"
117 #endif
118 
119 #if check(generic_lambdas, 0, 0, 201304, 201304)
120 #error "wrong value for __cpp_generic_lambdas"
121 #endif
122 
123 #if check(sized_deallocation, 0, 0, 201309, 201309)
124 #error "wrong value for __cpp_sized_deallocation"
125 #endif
126 
127 // constexpr checked below
128 
129 #if check(decltype_auto, 0, 0, 201304, 201304)
130 #error "wrong value for __cpp_decltype_auto"
131 #endif
132 
133 #if check(return_type_deduction, 0, 0, 201304, 201304)
134 #error "wrong value for __cpp_return_type_deduction"
135 #endif
136 
137 #if check(runtime_arrays, 0, 0, 0, 0)
138 #error "wrong value for __cpp_runtime_arrays"
139 #endif
140 
141 #if check(aggregate_nsdmi, 0, 0, 201304, 201304)
142 #error "wrong value for __cpp_aggregate_nsdmi"
143 #endif
144 
145 #if check(variable_templates, 0, 0, 201304, 201304)
146 #error "wrong value for __cpp_variable_templates"
147 #endif
148 
149 // --- C++11 features ---
150 
151 #if check(unicode_characters, 0, 200704, 200704, 200704)
152 #error "wrong value for __cpp_unicode_characters"
153 #endif
154 
155 #if check(raw_strings, 0, 200710, 200710, 200710)
156 #error "wrong value for __cpp_raw_strings"
157 #endif
158 
159 #if check(unicode_literals, 0, 200710, 200710, 200710)
160 #error "wrong value for __cpp_unicode_literals"
161 #endif
162 
163 #if check(user_defined_literals, 0, 200809, 200809, 200809)
164 #error "wrong value for __cpp_user_defined_literals"
165 #endif
166 
167 #if defined(NO_THREADSAFE_STATICS) ? check(threadsafe_static_init, 0, 0, 0, 0) : check(threadsafe_static_init, 200806, 200806, 200806, 200806)
168 #error "wrong value for __cpp_threadsafe_static_init"
169 #endif
170 
171 #if check(lambdas, 0, 200907, 200907, 200907)
172 #error "wrong value for __cpp_lambdas"
173 #endif
174 
175 #if check(constexpr, 0, 200704, 201304, 201603)
176 #error "wrong value for __cpp_constexpr"
177 #endif
178 
179 #if check(range_based_for, 0, 200907, 200907, 201603)
180 #error "wrong value for __cpp_range_based_for"
181 #endif
182 
183 #if check(static_assert, 0, 200410, 200410, 201411)
184 #error "wrong value for __cpp_static_assert"
185 #endif
186 
187 #if check(decltype, 0, 200707, 200707, 200707)
188 #error "wrong value for __cpp_decltype"
189 #endif
190 
191 #if check(attributes, 0, 200809, 200809, 200809)
192 #error "wrong value for __cpp_attributes"
193 #endif
194 
195 #if check(rvalue_references, 0, 200610, 200610, 200610)
196 #error "wrong value for __cpp_rvalue_references"
197 #endif
198 
199 #if check(variadic_templates, 0, 200704, 200704, 200704)
200 #error "wrong value for __cpp_variadic_templates"
201 #endif
202 
203 #if check(initializer_lists, 0, 200806, 200806, 200806)
204 #error "wrong value for __cpp_initializer_lists"
205 #endif
206 
207 #if check(delegating_constructors, 0, 200604, 200604, 200604)
208 #error "wrong value for __cpp_delegating_constructors"
209 #endif
210 
211 #if check(nsdmi, 0, 200809, 200809, 200809)
212 #error "wrong value for __cpp_nsdmi"
213 #endif
214 
215 #if check(inheriting_constructors, 0, 201511, 201511, 201511)
216 #error "wrong value for __cpp_inheriting_constructors"
217 #endif
218 
219 #if check(ref_qualifiers, 0, 200710, 200710, 200710)
220 #error "wrong value for __cpp_ref_qualifiers"
221 #endif
222 
223 #if check(alias_templates, 0, 200704, 200704, 200704)
224 #error "wrong value for __cpp_alias_templates"
225 #endif
226 
227 // --- C++98 features ---
228 
229 #if defined(NO_RTTI) ? check(rtti, 0, 0, 0, 0) : check(rtti, 199711, 199711, 199711, 199711)
230 #error "wrong value for __cpp_rtti"
231 #endif
232 
233 #if defined(NO_EXCEPTIONS) ? check(exceptions, 0, 0, 0, 0) : check(exceptions, 199711, 199711, 199711, 199711)
234 #error "wrong value for __cpp_exceptions"
235 #endif
236 
237 // --- TS features --
238 
239 #if check(experimental_concepts, 0, 0, CONCEPTS_TS, CONCEPTS_TS)
240 #error "wrong value for __cpp_experimental_concepts"
241 #endif
242 
243 #if defined(COROUTINES) ? check(coroutines, 201703L, 201703L, 201703L, 201703L) : check(coroutines, 0, 0, 0, 0)
244 #error "wrong value for __cpp_coroutines"
245 #endif
246 
247 // --- not-yet-standard features --
248 
249 #if defined(CHAR8_T) ? check(char8_t, 201803, 201803, 201803, 201803) : check(char8_t, 0, 0, 0, 0)
250 #error "wrong value for __cpp_char8_t"
251 #endif
252