Debian Codegraph @

clang/test/AST/ByteCode/libcxx/deref-to-array.cpp

raw
1 // RUN: %clang_cc1 -std=c++2c -fexperimental-new-constant-interpreter -verify=expected,both %s
2 // RUN: %clang_cc1 -std=c++2c -verify=ref,both %s
3
4 // both-no-diagnostics
5
6 namespace std {
7 inline namespace {
8 template <class _Tp, _Tp __v> struct integral_constant {
9 static const _Tp value = __v;
10 };
11 template <bool _Val> using _BoolConstant = integral_constant<bool, _Val>;
12 template <class _Tp> using __remove_cv_t = __remove_cv(_Tp);
13 template <class _Tp> using remove_cv_t = __remove_cv_t<_Tp>;
14 template <class _From, class _To>
15 constexpr bool is_convertible_v = __is_convertible(_From, _To);
16 template <class _Tp> _Tp __declval(long);
17 template <class _Tp> decltype(__declval<_Tp>(0)) declval();
18 template <class _From, class _To>
19 concept convertible_to = is_convertible_v<_From, _To> &&
20 requires { static_cast<_To>(declval<_From>()); };
21 template <class _Tp> constexpr bool is_reference_v = __is_reference(_Tp);
22 template <class _Tp>
23 constexpr bool is_lvalue_reference_v = __is_lvalue_reference(_Tp);
24 template <class>
25 constexpr bool is_nothrow_destructible_v =
26 integral_constant<bool, __is_nothrow_destructible(int)>::value;
27 template <class _Tp>
28 concept destructible = is_nothrow_destructible_v<_Tp>;
29 template <class _Tp, class _Up>
30 using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>;
31 template <class... _Args>
32 constexpr bool is_constructible_v = __is_constructible(_Args...);
33 template <class _Tp, class... _Args>
34 concept constructible_from = destructible<_Tp> && is_constructible_v<_Tp>;
35 template <class _Tp>
36 concept move_constructible =
37 constructible_from<_Tp, _Tp> && convertible_to<_Tp, _Tp>;
38 template <class _Tp, class _Up>
39 concept __same_as_impl = _IsSame<_Tp, _Up>::value;
40 template <class _Tp, class _Up>
41 concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>;
42 template <bool> struct _IfImpl;
43 template <> struct _IfImpl<false> {
44 template <class, class _ElseRes> using _Select = _ElseRes;
45 };
46 template <bool _Cond, class _IfRes, class _ElseRes>
47 using _If = _IfImpl<_Cond>::template _Select<_IfRes, _ElseRes>;
48 template <class _If> struct conditional {
49 using type = _If;
50 };
51 template <bool, class _IfRes, class>
52 using conditional_t = conditional<_IfRes>::type;
53 template <class _Tp>
54 using __libcpp_remove_reference_t = __remove_reference_t(_Tp);
55 template <class _Tp>
56 using remove_reference_t = __libcpp_remove_reference_t<_Tp>;
57 template <class _Tp> using __decay_t = __decay(_Tp);
58 template <class _Tp> using __remove_cvref_t = __remove_cvref(_Tp);
59 template <class _Tp> using remove_cvref_t = __remove_cvref_t<_Tp>;
60 struct __copy_cv {
61 template <class _To> using __apply = _To;
62 };
63 template <class, class _To> using __copy_cv_t = __copy_cv::__apply<_To>;
64 template <class _Xp, class _Yp>
65 using __cond_res =
66 decltype(false ? std::declval<_Xp (&)()>()() : std::declval<_Yp (&)()>()());
67 template <class _Ap, class _Bp, class = remove_reference_t<_Ap>,
68 class = remove_reference_t<_Bp>>
69 struct __common_ref;
70 template <class _Ap, class _Bp, class, class>
71 struct __common_ref : __common_ref<_Bp, _Ap> {};
72 template <class _Xp, class _Yp>
73 using __common_ref_t = __common_ref<_Xp, _Yp>::__type;
74 template <class _Xp, class _Yp>
75 using __cv_cond_res =
76 __cond_res<__copy_cv_t<_Xp, _Yp> &, __copy_cv_t<_Yp, _Xp> &>;
77 template <class _Ap, class _Bp, class _Xp, class _Yp>
78 requires requires { typename __cv_cond_res<_Xp, _Yp>; } &&
79 is_reference_v<__cv_cond_res<_Xp, _Yp>>
80 struct __common_ref<_Ap, _Bp &, _Xp, _Yp> {
81 using __type = __cv_cond_res<_Xp, _Yp>;
82 };
83 template <class _Tp, class _Up>
84 using __common_ref_D = __common_ref_t<const _Tp, _Up &>;
85 template <class _Ap, class _Bp, class _Xp, class _Yp>
86 requires requires { typename __common_ref_D<_Xp, _Yp>; } &&
87 is_convertible_v<_Ap, __common_ref_D<_Xp, _Yp>>
88 struct __common_ref<_Ap &&, _Bp &, _Xp, _Yp> {
89 using __type = __common_ref_D<_Xp, _Yp>;
90 };
91 template <class...> struct common_reference;
92 template <class... _Types>
93 using common_reference_t = common_reference<_Types...>::type;
94 template <class, class> struct __common_reference_sub_bullet1;
95 template <class _Tp, class _Up>
96 struct common_reference<_Tp, _Up> : __common_reference_sub_bullet1<_Tp, _Up> {};
97 template <class _Tp, class _Up>
98 requires is_reference_v<_Tp> && is_reference_v<_Up> &&
99 requires { typename __common_ref_t<_Tp, _Up>; }
100 struct __common_reference_sub_bullet1<_Tp, _Up> {
101 using type = __common_ref_t<_Tp, _Up>;
102 };
103 template <class _Tp, class _Up>
104 concept common_reference_with =
105 same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>> &&
106 convertible_to<_Tp, common_reference_t<_Tp, _Up>> &&
107 convertible_to<_Up, common_reference_t<_Tp, _Up>>;
108 template <class _Tp>
109 using __make_const_lvalue_ref = __libcpp_remove_reference_t<_Tp> &;
110 template <class _Lhs, class _Rhs>
111 concept assignable_from =
112 is_lvalue_reference_v<_Lhs> &&
113 common_reference_with<__make_const_lvalue_ref<_Lhs>,
114 __make_const_lvalue_ref<_Rhs>> &&
115 requires(_Lhs __lhs, _Rhs __rhs) {
116 { __rhs } -> same_as<_Lhs>;
117 };
118 template <class _Tp> constexpr __libcpp_remove_reference_t<_Tp> &&move(_Tp &&);
119 typedef int type;
120 template <bool, class = void> using __enable_if_t = type;
121 namespace ranges {
122 inline namespace {
123 auto swap = int{};
124 }
125 } // namespace ranges
126 template <class _Tp> constexpr bool is_object_v = __is_object(_Tp);
127 template <class _Tp>
128 concept movable = is_object_v<_Tp> && move_constructible<_Tp> &&
129 assignable_from<_Tp &, _Tp>;
130 template <decltype(sizeof(int)), class> struct tuple_element;
131 template <class...> class tuple;
132 template <template <class> class _Templ, class... _Args,
133 class = _Templ<_Args...>>
134 integral_constant<bool, true> __sfinae_test_impl(int);
135 template <template <class> class, class>
136 integral_constant<bool, false> __sfinae_test_impl(...);
137 template <template <class> class _Templ, class... _Args>
138 using _IsValidExpansion =
139 decltype(std::__sfinae_test_impl<_Templ, _Args...>(0));
140 template <class _Tp>
141 using __test_for_primary_template =
142 __enable_if_t<_IsSame<_Tp, typename _Tp::__primary_template>::value>;
143 template <class _Tp>
144 using __is_primary_template =
145 _IsValidExpansion<__test_for_primary_template, _Tp>;
146 template <class> struct iterator_traits;
147 template <class> struct __cond_value_type;
148 template <class _Tp>
149 requires is_object_v<_Tp>
150 struct __cond_value_type<_Tp> {
151 using value_type = remove_cv_t<_Tp>;
152 };
153 template <class> struct indirectly_readable_traits;
154 template <class _Tp>
155 struct indirectly_readable_traits<_Tp *> : __cond_value_type<_Tp> {};
156 template <bool> struct _OrImpl;
157 template <> struct _OrImpl<true> {
158 template <class, class _First, class... _Rest>
159 using _Result = _OrImpl<!(_First::value) &&
160 sizeof...(_Rest)>::template _Result<_First, _Rest...>;
161 };
162 template <> struct _OrImpl<false> {
163 template <class _Res, class...> using _Result = _Res;
164 };
165 template <class... _Args>
166 using _Or =
167 _OrImpl<sizeof...(_Args) !=
168 0>::template _Result<integral_constant<bool, false>, _Args...>;
169 template <class _Tp> using __with_reference = _Tp;
170 template <class _Tp>
171 concept __can_reference = requires { typename __with_reference<_Tp>; };
172 template <class _Tp>
173 concept __dereferenceable = requires(_Tp __t) {
174 { __t };
175 };
176 template <__dereferenceable _Tp>
177 using iter_reference_t = decltype(*std::declval<_Tp>());
178 struct input_iterator_tag {};
179 struct contiguous_iterator_tag : input_iterator_tag {};
180 template <class> struct __iter_traits_cache {
181 using type = _If<__is_primary_template<iterator_traits<int>>::value, int,
182 iterator_traits<int>>;
183 };
184 template <class _Iter> using _ITER_TRAITS = __iter_traits_cache<_Iter>::type;
185 struct __iter_concept_concept_test {
186 template <class _Iter> using _Apply = _ITER_TRAITS<_Iter>::iterator_concept;
187 };
188 template <class, class _Tester>
189 struct __test_iter_concept : _IsValidExpansion<_Tester::template _Apply, int>,
190 _Tester {};
191 template <class _Iter> struct __iter_concept_cache {
192 using type =
193 _Or<__test_iter_concept<_Iter, __iter_concept_concept_test>,
194 __test_iter_concept<_Iter, int>, __test_iter_concept<_Iter, int>>;
195 };
196 template <class _Iter>
197 using _ITER_CONCEPT = __iter_concept_cache<_Iter>::type::template _Apply<_Iter>;
198 template <class _Tp>
199 requires is_object_v<_Tp>
200 struct iterator_traits<_Tp> {
201 typedef contiguous_iterator_tag iterator_concept;
202 };
203 template <class _Ip>
204 using iter_value_t = conditional_t<
205 __is_primary_template<iterator_traits<remove_cvref_t<_Ip>>>::value,
206 indirectly_readable_traits<remove_cvref_t<_Ip>>,
207 iterator_traits<remove_cvref_t<_Ip>>>::value_type;
208 template <class _Tp> _Tp *addressof(_Tp &);
209 template <class _Bp, class _Dp>
210 constexpr bool is_base_of_v = __is_base_of(_Bp, _Dp);
211 template <class _Dp, class _Bp>
212 concept derived_from = is_base_of_v<_Bp, _Dp> && is_convertible_v<_Dp *, _Bp *>;
213 namespace ranges {
214 struct Trans_NS___iter_move___fn {
215 template <class _Ip>
216 auto operator()(_Ip __i) -> decltype(std::move(*__i));
217 };
218 auto iter_move = Trans_NS___iter_move___fn{};
219 } // namespace ranges
220 template <__dereferenceable _Tp>
221 requires requires {
222 { ranges::iter_move };
223 }
224 using iter_rvalue_reference_t =
225 decltype(ranges::iter_move(std::declval<_Tp>()));
226 template <class _In>
227 concept __indirectly_readable_impl =
228 requires { typename iter_value_t<_In>; } &&
229 common_reference_with<iter_reference_t<_In>, iter_value_t<_In> &> &&
230 common_reference_with<iter_reference_t<_In>,
231 iter_rvalue_reference_t<_In>> &&
232 common_reference_with<iter_rvalue_reference_t<_In>, iter_value_t<_In> &>;
233 template <class _In>
234 concept indirectly_readable = __indirectly_readable_impl<remove_cvref_t<_In>>;
235 template <class _Ip>
236 concept weakly_incrementable =
237 !same_as<_Ip, bool> && movable<_Ip> && requires(_Ip __i) { __i; };
238 template <class _Ip>
239 concept input_or_output_iterator = requires(_Ip __i) {
240 { __i };
241 } && weakly_incrementable<_Ip>;
242 template <class _Ip>
243 concept input_iterator =
244 input_or_output_iterator<_Ip> && indirectly_readable<_Ip> && requires {
245 typename _ITER_CONCEPT<_Ip>;
246 } && derived_from<_ITER_CONCEPT<_Ip>, input_iterator_tag>;
247 namespace ranges {
248 struct __fn {
249 template <class _Tp, decltype(sizeof(int)) _Np>
250 constexpr auto operator()(_Tp (&__t)[_Np]) const
251 {
252 return __t;
253 }
254 template <class _Tp> constexpr auto operator()(_Tp __t) const {
255 return static_cast<std::__decay_t<decltype((__t.begin()))>>(__t.begin());
256 }
257 };
258 inline namespace {
259 auto begin = __fn{};
260 }
261 template <class _Tp>
262 using iterator_t = decltype(ranges::begin(std::declval<_Tp &>()));
263 inline namespace {
264 auto end = int{};
265 }
266 template <class _Derived>
267 class view_interface;
268 template <class _Op, class _Yp>
269 requires is_convertible_v<_Op, view_interface<_Yp>>
270 void __is_derived_from_view_interface();
271 template <class _Tp>
272 bool enable_view = derived_from<_Tp, int> ||
273 requires { ranges::__is_derived_from_view_interface<_Tp, int>(); };
274 template <class>
275 concept range = requires { ranges::end; };
276 template <class _Tp>
277 concept input_range = range<_Tp> && input_iterator<iterator_t<_Tp>>;
278 template <class _Tp>
279 concept view = range<_Tp> && movable<_Tp> && enable_view<_Tp>;
280 template <class _Tp>
281 concept viewable_range =
282 range<_Tp> &&
283 ((view<remove_cvref_t<_Tp>> && constructible_from<remove_cvref_t<_Tp>>) ||
284 (!view<remove_cvref_t<_Tp>> && (is_lvalue_reference_v<_Tp>)));
285 } // namespace ranges
286 template <decltype(sizeof(int))...> struct __tuple_indices;
287 template <class _IdxType, _IdxType... _Values> struct __integer_sequence {
288 template <decltype(sizeof(int)) _Sp>
289 using __to_tuple_indices = __tuple_indices<(_Values)...>;
290 };
291 template <decltype(sizeof(int)) _Ep, decltype(sizeof(int)) _Sp>
292 using __make_indices_imp =
293 __make_integer_seq<__integer_sequence, decltype(sizeof(int)),
294 _Sp>::template __to_tuple_indices<_Sp>;
295 template <int _Ep, decltype(sizeof(int)) _Sp = 0> struct __make_tuple_indices {
296 typedef __make_indices_imp<_Ep, _Sp> type;
297 };
298 template <class...> struct __tuple_types;
299 namespace ranges {
300 template <class _Derived>
301 class view_interface {};
302 } // namespace ranges
303 template <decltype(sizeof(int)) _Ip, class... _Types>
304 struct tuple_element<_Ip, __tuple_types<_Types...>> {
305 using type = __type_pack_element<_Ip, _Types...>;
306 };
307 template <decltype(sizeof(int)) _Ip, class... _Tp>
308 struct tuple_element<_Ip, tuple<_Tp...>> {
309 using type = tuple_element<_Ip, __tuple_types<_Tp...>>::type;
310 };
311
312 template <class... _Tp> struct tuple {
313 int __value_;
314 constexpr int get() { return __value_; }
315 };
316 template <int _Ip, class... _Tp> constexpr void get(tuple<_Tp...> __t) {
317 __t.get();
318 }
319 namespace ranges {
320 template <class _Tp>
321 struct __range_adaptor_closure {};
322 template <range _Range>
323 requires is_object_v<_Range>
324 struct ref_view : view_interface<ref_view<_Range>> {
325 _Range *__range_;
326
327 template <class _Tp>
328 constexpr ref_view(_Tp &&__t)
329 : __range_(std::addressof(static_cast<_Range &>(__t))) {}
330 constexpr iterator_t<_Range> begin() { return ranges::begin(*__range_); }
331 };
332 template <class _Range> ref_view(_Range &) -> ref_view<_Range>;
333 } // namespace ranges
334 namespace ranges::views {
335 struct __fn : __range_adaptor_closure<__fn> {
336 template <class _Tp> auto operator()(_Tp &&__t) const {
337 return ranges::ref_view{__t};
338 }
339 };
340 inline namespace {
341 auto all = __fn{};
342 }
343 template <ranges::viewable_range _Range>
344 using all_t = decltype(views::all(std::declval<_Range>()));
345 } // namespace ranges::views
346 namespace ranges {
347 template <input_range _View, decltype(sizeof(int)) _Np>
348 struct elements_view : view_interface<elements_view<_View, _Np>> {
349 class __iterator;
350
351 constexpr elements_view(_View __base) : __base_(std::move(__base)) {}
352 constexpr auto begin() const { return __iterator(ranges::begin(__base_)); }
353
354 _View __base_ = _View();
355 };
356 template <input_range _View, decltype(sizeof(int)) _Np>
357 struct elements_view<_View, _Np>::__iterator {
358 iterator_t<_View> __current_;
359
360 constexpr void operator*() {
361 auto a = *__current_;
362 }
363 };
364 namespace views {
365 namespace __elements {
366 template <int _Np> struct __fn : __range_adaptor_closure<__fn<_Np>> {
367 template <class _Range>
368 constexpr auto operator()(_Range &&__range) const
369 -> decltype(elements_view<all_t<_Range>, _Np>(__range)) {
370 return elements_view<all_t<_Range>, _Np>(__range);
371 }
372 };
373 } // namespace __elements
374 inline namespace {
375 template <decltype(sizeof(int)) _Np> auto elements = __elements::__fn<_Np>{};
376 }
377 } // namespace views
378 } // namespace ranges
379 } // namespace
380 } // namespace std
381 constexpr bool test() {
382 std::tuple<short, long> ts[]{{}};
383
384
385 auto ev = std::ranges::views::elements<1>(ts);
386 auto it = ev.begin();
387
388 *it;
389 return true;
390 }
391 static_assert(test());