2 // { dg-options "-O2 -fno-inline -fdump-final-insns" }
3 // { dg-do compile { target c++11 } }
4 // { dg-final cleanup-final-insns-dump }
5 // { dg-additional-options "-Wno-return-type" }
9 typedef __SIZE_TYPE__ size_t;
10 typedef __PTRDIFF_TYPE__ ptrdiff_t;
13 void* operator new(std::size_t, void* __p) noexcept;
15 namespace std __attribute__ ((__visibility__ ("default")))
17 template<typename _Tp, _Tp __v>
18 struct integral_constant
20 static constexpr _Tp value = __v;
21 typedef integral_constant<_Tp, __v> type;
23 typedef integral_constant<bool, true> true_type;
24 typedef integral_constant<bool, false> false_type;
25 template<bool, typename, typename>
29 template<typename _B1, typename _B2>
30 struct __or_<_B1, _B2>
31 : public conditional<_B1::value, _B1, _B2>::type
33 template<typename _B1, typename _B2, typename _B3, typename... _Bn>
34 struct __or_<_B1, _B2, _B3, _Bn...>
35 : public conditional<_B1::value, _B1, __or_<_B2, _B3, _Bn...>>::type
39 template<typename _B1, typename _B2>
40 struct __and_<_B1, _B2>
41 : public conditional<_B1::value, _B2, _B1>::type
43 template<typename _Pp>
45 : public integral_constant<bool, !_Pp::value>
47 template<typename _Tp>
49 { typedef _Tp type; };
53 struct __is_void_helper
54 : public false_type {};
55 template<typename _Tp>
57 : public __is_void_helper<typename remove_cv<_Tp>::type>::type
60 struct __is_integral_helper
61 : public true_type {};
62 template<typename _Tp>
64 : public __is_integral_helper<typename remove_cv<_Tp>::type>::type
68 : public false_type {};
70 struct is_lvalue_reference
71 : public false_type {};
73 struct is_rvalue_reference
74 : public false_type {};
76 struct __is_member_object_pointer_helper
77 : public false_type {};
78 template<typename _Tp>
79 struct is_member_object_pointer
80 : public __is_member_object_pointer_helper<
81 typename remove_cv<_Tp>::type>::type
84 struct __is_member_function_pointer_helper
85 : public false_type {};
86 template<typename _Tp>
87 struct is_member_function_pointer
88 : public __is_member_function_pointer_helper<
89 typename remove_cv<_Tp>::type>::type
91 template<typename _Tp>
93 : public integral_constant<bool, __is_enum(_Tp)>
97 : public false_type {};
98 template<typename _Tp>
100 : public __or_<is_lvalue_reference<_Tp>,
101 is_rvalue_reference<_Tp>>::type
103 template<typename _Tp>
104 struct __is_member_pointer_helper
105 : public false_type {};
106 template<typename _Tp>
107 struct is_member_pointer
108 : public __is_member_pointer_helper<typename remove_cv<_Tp>::type>::type
112 : public false_type {};
115 : public false_type {};
117 struct add_rvalue_reference;
118 template<typename _Tp>
119 typename add_rvalue_reference<_Tp>::type declval() noexcept;
120 struct __do_is_nary_constructible_impl
122 template<typename _Tp, typename... _Args, typename
123 = decltype(_Tp(declval<_Args>()...))>
124 static true_type __test(int);
126 template<typename _Tp, typename... _Args>
127 struct __is_nary_constructible_impl
128 : public __do_is_nary_constructible_impl
130 typedef decltype(__test<_Tp, _Args...>(0)) type;
132 template<typename _Tp, typename... _Args>
133 struct __is_nary_constructible
134 : public __is_nary_constructible_impl<_Tp, _Args...>::type
136 template<typename _Tp, typename... _Args>
137 struct __is_constructible_impl
138 : public __is_nary_constructible<_Tp, _Args...>
140 template<typename _Tp, typename... _Args>
141 struct is_constructible
142 : public __is_constructible_impl<_Tp, _Args...>::type
144 template<typename, typename>
146 : public true_type {};
147 template<typename _From, typename _To,
148 bool = __or_<is_void<_From>, is_function<_To>,
149 is_array<_To>>::value>
150 struct __is_convertible_helper
152 template<typename _To1>
153 static void __test_aux(_To1);
154 template<typename _From1, typename _To1,
155 typename = decltype(__test_aux<_To1>(std::declval<_From1>()))>
158 typedef decltype(__test<_From, _To>(0)) type;
160 template<typename _From, typename _To>
161 struct is_convertible
162 : public __is_convertible_helper<_From, _To>::type
164 template<typename _Tp>
166 { typedef _Tp type; };
167 template<typename _Tp>
168 struct remove_volatile
169 { typedef _Tp type; };
170 template<typename _Tp>
174 remove_const<typename remove_volatile<_Tp>::type>::type type;
176 template<typename _Tp>
177 struct remove_reference
178 { typedef _Tp type; };
179 template<typename _Tp>
180 struct remove_reference<_Tp&>
181 { typedef _Tp type; };
182 template<typename _Tp,
183 bool = __and_<__not_<is_reference<_Tp>>,
184 __not_<is_void<_Tp>>>::value>
185 struct __add_rvalue_reference_helper
186 { typedef _Tp type; };
187 template<typename _Tp>
188 struct add_rvalue_reference
189 : public __add_rvalue_reference_helper<_Tp>
191 template<typename _Unqualified, bool _IsConst, bool _IsVol>
192 struct __cv_selector;
193 template<typename _Unqualified>
194 struct __cv_selector<_Unqualified, false, false>
195 { typedef _Unqualified __type; };
196 template<typename _Qualified, typename _Unqualified,
197 bool _IsConst = is_const<_Qualified>::value,
198 bool _IsVol = is_volatile<_Qualified>::value>
199 class __match_cv_qualifiers
201 typedef __cv_selector<_Unqualified, _IsConst, _IsVol> __match;
203 typedef typename __match::__type __type;
205 template<typename _Tp>
206 struct __make_unsigned
207 { typedef _Tp __type; };
208 template<typename _Tp,
209 bool _IsInt = is_integral<_Tp>::value,
210 bool _IsEnum = is_enum<_Tp>::value>
211 class __make_unsigned_selector;
212 template<typename _Tp>
213 class __make_unsigned_selector<_Tp, true, false>
215 typedef __make_unsigned<typename remove_cv<_Tp>::type> __unsignedt;
216 typedef typename __unsignedt::__type __unsigned_type;
217 typedef __match_cv_qualifiers<_Tp, __unsigned_type> __cv_unsigned;
219 typedef typename __cv_unsigned::__type __type;
221 template<typename _Tp>
223 { typedef typename __make_unsigned_selector<_Tp>::__type type; };
224 template<typename _Tp, typename>
225 struct __remove_pointer_helper
226 { typedef _Tp type; };
227 template<typename _Tp>
228 struct remove_pointer
229 : public __remove_pointer_helper<_Tp, typename remove_cv<_Tp>::type>
231 template<typename _Up,
232 bool _IsArray = is_array<_Up>::value,
233 bool _IsFunction = is_function<_Up>::value>
234 struct __decay_selector;
235 template<typename _Up>
236 struct __decay_selector<_Up, false, false>
237 { typedef typename remove_cv<_Up>::type __type; };
238 template<typename _Tp>
241 typedef typename remove_reference<_Tp>::type __remove_type;
243 typedef typename __decay_selector<__remove_type>::__type type;
245 template<bool, typename _Tp = void>
247 { typedef _Tp type; };
248 template<typename... _Cond>
249 using _Require = typename enable_if<__and_<_Cond...>::value>::type;
250 template<bool _Cond, typename _Iftrue, typename _Iffalse>
252 { typedef _Iftrue type; };
253 template<typename _Signature>
255 template<bool, bool, typename _Functor, typename... _ArgTypes>
256 struct __result_of_impl
258 struct __result_of_other_impl
260 template<typename _Fn, typename... _Args>
261 static __success_type<decltype(
262 std::declval<_Fn>()(std::declval<_Args>()...)
265 template<typename _Functor, typename... _ArgTypes>
266 struct __result_of_impl<false, false, _Functor, _ArgTypes...>
267 : private __result_of_other_impl
269 typedef decltype(_S_test<_Functor, _ArgTypes...>(0)) type;
271 template<typename _Functor, typename... _ArgTypes>
272 struct result_of<_Functor(_ArgTypes...)>
273 : public __result_of_impl<
274 is_member_object_pointer<
275 typename remove_reference<_Functor>::type
277 is_member_function_pointer<
278 typename remove_reference<_Functor>::type
280 _Functor, _ArgTypes...
283 template<typename _Tp>
285 forward(typename std::remove_reference<_Tp>::type& __t) noexcept
286 { return static_cast<_Tp&&>(__t); }
287 template<typename _Tp>
288 constexpr typename std::remove_reference<_Tp>::type&&
289 move(_Tp&& __t) noexcept
290 { return static_cast<typename std::remove_reference<_Tp>::type&&>(__t); }
291 template<std::size_t _Int, class _Tp>
293 struct allocator_arg_t {};
294 constexpr allocator_arg_t allocator_arg = allocator_arg_t();
295 template<typename _Tp>
297 { typedef _Tp& type; };
298 template<std::size_t _Idx, typename... _Elements>
300 template<std::size_t _Idx, typename _Head, typename... _Tail>
301 struct _Tuple_impl<_Idx, _Head, _Tail...>
303 template<typename... _Elements>
304 class tuple : public _Tuple_impl<0, _Elements...>
306 template<typename _Head, typename... _Tail>
307 struct tuple_element<0, tuple<_Head, _Tail...> >
311 template<std::size_t __i, typename... _Elements>
313 typename tuple_element<__i, tuple<_Elements...>>::type
315 get(tuple<_Elements...>& __t) noexcept;
316 template<std::size_t... _Indexes>
319 template<std::size_t _Num>
320 struct _Build_index_tuple
322 typedef _Index_tuple<> __type;
324 template<typename _Functor, typename... _Args>
326 (!is_member_pointer<_Functor>::value
327 && !is_function<typename remove_pointer<_Functor>::type>::value),
328 typename result_of<_Functor(_Args&&...)>::type
330 __invoke(_Functor& __f, _Args&&... __args)
332 return __f(std::forward<_Args>(__args)...);
335 template<typename _Tp>
336 class reference_wrapper
342 template<typename... _Args>
343 typename result_of<_Tp&(_Args&&...)>::type
344 operator()(_Args&&... __args) const
346 return __invoke(get(), std::forward<_Args>(__args)...);
349 template<typename _Tp>
350 inline reference_wrapper<_Tp>
351 ref(_Tp& __t) noexcept
352 { return reference_wrapper<_Tp>(); }
353 template<typename _Tp>
354 struct _Maybe_wrap_member_pointer
358 template<typename _Signature>
360 template<typename _Callable, typename... _Args>
361 struct _Bind_simple<_Callable(_Args...)>
363 typedef typename result_of<_Callable(_Args...)>::type result_type;
367 typedef typename _Build_index_tuple<sizeof...(_Args)>::__type _Indices;
368 return _M_invoke(_Indices());
370 template<std::size_t... _Indices>
371 typename result_of<_Callable(_Args...)>::type
372 _M_invoke(_Index_tuple<_Indices...>)
374 return std::forward<_Callable>(std::get<0>(_M_bound))(
375 std::forward<_Args>(std::get<_Indices+1>(_M_bound))...);
377 std::tuple<_Callable, _Args...> _M_bound;
379 template<typename _Func, typename... _BoundArgs>
380 struct _Bind_simple_helper
382 typedef _Maybe_wrap_member_pointer<typename decay<_Func>::type>
384 typedef typename __maybe_type::type __func_type;
385 typedef _Bind_simple<__func_type(typename decay<_BoundArgs>::type...)>
388 template<typename _Callable, typename... _Args>
389 typename _Bind_simple_helper<_Callable, _Args...>::__type
390 __bind_simple(_Callable&& __callable, _Args&&... __args)
394 template<typename _Functor>
396 __callable_functor(_Functor& __f)
398 template<typename _Signature>
402 template<typename _Functor>
407 _M_get_pointer(const _Any_data& __source)
411 template<typename _Signature, typename _Functor>
412 class _Function_handler;
413 template<typename _Res, typename _Functor, typename... _ArgTypes>
414 class _Function_handler<_Res(_ArgTypes...), _Functor>
415 : public _Function_base::_Base_manager<_Functor>
417 typedef _Function_base::_Base_manager<_Functor> _Base;
420 _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
422 return (*_Base::_M_get_pointer(__functor))(
423 std::forward<_ArgTypes>(__args)...);
426 template<typename _Res, typename... _ArgTypes>
427 class function<_Res(_ArgTypes...)>
429 typedef _Res _Signature_type(_ArgTypes...);
430 template<typename _Functor>
431 using _Invoke = decltype(__callable_functor(std::declval<_Functor&>())
432 (std::declval<_ArgTypes>()...) );
433 template<typename _CallRes, typename _Res1>
435 : is_convertible<_CallRes, _Res1> {};
436 template<typename _Functor>
437 using _Callable = _CheckResult<_Invoke<_Functor>, _Res>;
438 template<typename _Cond, typename _Tp>
439 using _Requires = typename enable_if<_Cond::value, _Tp>::type;
441 template<typename _Functor,
442 typename = _Requires<_Callable<_Functor>, void>>
444 typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...);
445 _Invoker_type _M_invoker;
447 template<typename _Res, typename... _ArgTypes>
448 template<typename _Functor, typename>
449 function<_Res(_ArgTypes...)>::
450 function(_Functor __f)
452 typedef _Function_handler<_Signature_type, _Functor> _My_handler;
454 _M_invoker = &_My_handler::_M_invoke;
457 template<typename _Ptr>
458 class __ptrtr_pointer_to
460 template<typename _Ptr>
461 struct pointer_traits : __ptrtr_pointer_to<_Ptr>
463 template<typename _Tp>
464 struct pointer_traits<_Tp*>
466 typedef ptrdiff_t difference_type;
468 template<typename _Alloc, typename _Tp>
469 class __alloctr_rebind_helper
471 template<typename, typename>
472 static constexpr bool
476 static const bool __value = _S_chk<_Alloc, _Tp>(nullptr);
478 template<typename _Alloc, typename _Tp,
479 bool = __alloctr_rebind_helper<_Alloc, _Tp>::__value>
480 struct __alloctr_rebind;
481 template<template<typename, typename...> class _Alloc, typename _Tp,
482 typename _Up, typename... _Args>
483 struct __alloctr_rebind<_Alloc<_Up, _Args...>, _Tp, false>
485 typedef _Alloc<_Tp, _Args...> __type;
487 template<typename _Alloc>
488 struct allocator_traits
490 typedef _Alloc allocator_type;
491 typedef typename _Alloc::value_type value_type; static value_type* _S_pointer_helper(...); typedef decltype(_S_pointer_helper((_Alloc*)0)) __pointer; public:
492 typedef __pointer pointer; static typename pointer_traits<pointer>::difference_type _S_difference_type_helper(...); typedef decltype(_S_difference_type_helper((_Alloc*)0)) __difference_type; public:
493 typedef __difference_type difference_type; static typename make_unsigned<difference_type>::type _S_size_type_helper(...); typedef decltype(_S_size_type_helper((_Alloc*)0)) __size_type; public:
494 typedef __size_type size_type; public:
495 template<typename _Tp>
496 using rebind_alloc = typename __alloctr_rebind<_Alloc, _Tp>::__type;
497 template<typename _Tp>
498 using rebind_traits = allocator_traits<rebind_alloc<_Tp>>;
499 template<typename _Tp, typename... _Args>
500 struct __construct_helper
503 static false_type __test(...);
504 typedef decltype(__test<_Alloc>(0)) type;
505 static const bool value = type::value;
507 template<typename _Tp, typename... _Args>
509 enable_if<__and_<__not_<__construct_helper<_Tp, _Args...>>,
510 is_constructible<_Tp, _Args...>>::value, void>::type
511 _S_construct(_Alloc&, _Tp* __p, _Args&&... __args)
512 { ::new((void*)__p) _Tp(std::forward<_Args>(__args)...); }
514 allocate(_Alloc& __a, size_type __n)
516 template<typename _Tp, typename... _Args>
517 static auto construct(_Alloc& __a, _Tp* __p, _Args&&... __args)
518 -> decltype(_S_construct(__a, __p, std::forward<_Args>(__args)...))
519 { _S_construct(__a, __p, std::forward<_Args>(__args)...); }
522 namespace __gnu_cxx __attribute__ ((__visibility__ ("default")))
524 enum _Lock_policy { _S_single, _S_mutex, _S_atomic };
525 static const _Lock_policy __default_lock_policy =
528 namespace std __attribute__ ((__visibility__ ("default")))
530 template<typename _Tp>
531 struct default_delete
533 template <typename _Tp, typename _Dp = default_delete<_Tp> >
538 template<typename _Up>
539 static _Tp* __test(...);
540 typedef typename remove_reference<_Dp>::type _Del;
542 typedef decltype(__test<_Del>(0)) type;
545 typedef typename _Pointer::type pointer;
546 typedef _Tp element_type;
547 template<typename _Up, typename _Ep, typename = _Require<
548 is_convertible<typename unique_ptr<_Up, _Ep>::pointer, pointer>,
549 typename conditional<is_reference<_Dp>::value,
551 is_convertible<_Ep, _Dp>>::type>>
552 unique_ptr(unique_ptr<_Up, _Ep>&& __u) noexcept
558 template<typename _Tp>
559 struct __aligned_buffer
562 namespace std __attribute__ ((__visibility__ ("default")))
564 using __gnu_cxx::_Lock_policy;
565 using __gnu_cxx::__default_lock_policy;
566 template<_Lock_policy _Lp = __default_lock_policy>
567 class _Sp_counted_base
569 template<typename _Tp, _Lock_policy _Lp = __default_lock_policy>
571 struct _Sp_make_shared_tag {};
572 template<typename _Tp, typename _Alloc, _Lock_policy _Lp>
573 class _Sp_counted_ptr_inplace final : public _Sp_counted_base<_Lp>
578 _Impl(_Alloc __a) : _Alloc(__a), _M_ptr() {}
582 template<typename... _Args>
583 _Sp_counted_ptr_inplace(_Alloc __a, _Args&&... __args)
584 : _M_impl(__a), _M_storage()
586 allocator_traits<_Alloc>::construct(__a, _M_impl._M_ptr,
587 std::forward<_Args>(__args)...);
590 __gnu_cxx::__aligned_buffer<_Tp> _M_storage;
592 template<_Lock_policy _Lp>
596 template<typename _Tp, typename _Alloc, typename... _Args>
597 __shared_count(_Sp_make_shared_tag, _Tp*, const _Alloc& __a,
600 typedef _Sp_counted_ptr_inplace<_Tp, _Alloc, _Lp> _Sp_cp_type;
601 typedef typename allocator_traits<_Alloc>::template
602 rebind_traits<_Sp_cp_type> _Alloc_traits;
603 typename _Alloc_traits::allocator_type __a2(__a);
604 _Sp_cp_type* __mem = _Alloc_traits::allocate(__a2, 1);
607 _Alloc_traits::construct(__a2, __mem, std::move(__a),
608 std::forward<_Args>(__args)...);
614 template<typename _Tp, _Lock_policy _Lp>
618 template<typename _Tp1, typename = typename
619 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
620 __shared_ptr(const __shared_ptr<_Tp1, _Lp>& __r) noexcept
621 : _M_ptr(__r._M_ptr), _M_refcount(__r._M_refcount)
623 template<typename _Alloc, typename... _Args>
624 __shared_ptr(_Sp_make_shared_tag __tag, const _Alloc& __a,
626 : _M_ptr(), _M_refcount(__tag, (_Tp*)0, __a,
627 std::forward<_Args>(__args)...)
630 __shared_count<_Lp> _M_refcount;
632 template<typename _Tp>
633 class shared_ptr : public __shared_ptr<_Tp>
636 template<typename _Tp1, typename = typename
637 std::enable_if<std::is_convertible<_Tp1*, _Tp*>::value>::type>
638 shared_ptr(const shared_ptr<_Tp1>& __r) noexcept
639 : __shared_ptr<_Tp>(__r) {}
640 template<typename _Alloc, typename... _Args>
641 shared_ptr(_Sp_make_shared_tag __tag, const _Alloc& __a,
643 : __shared_ptr<_Tp>(__tag, __a, std::forward<_Args>(__args)...)
646 template<typename _Tp, typename _Alloc, typename... _Args>
647 inline shared_ptr<_Tp>
648 allocate_shared(const _Alloc& __a, _Args&&... __args)
650 return shared_ptr<_Tp>(_Sp_make_shared_tag(), __a,
651 std::forward<_Args>(__args)...);
654 namespace std __attribute__ ((__visibility__ ("default")))
656 template<typename _Signature>
665 template<typename _Res>
666 struct _Result : _Result_base
668 typedef _Res result_type;
670 template<typename _Res>
671 using _Ptr = unique_ptr<_Res, _Result_base::_Deleter>;
672 template<typename _Res, typename _Alloc>
673 struct _Result_alloc final : _Result<_Res>, _Alloc
675 template<typename _Res, typename _Allocator>
676 static _Ptr<_Result_alloc<_Res, _Allocator>>
677 _S_allocate_result(const _Allocator& __a)
679 template<typename _Signature>
680 class _Task_state_base;
681 template<typename _Fn, typename _Alloc, typename _Signature>
683 template<typename _Res_ptr,
684 typename _Res = typename _Res_ptr::element_type::result_type>
686 template<typename _Res_ptr, typename _BoundFn>
687 static _Task_setter<_Res_ptr>
688 _S_task_setter(_Res_ptr& __ptr, _BoundFn&& __call)
690 return _Task_setter<_Res_ptr>{ __ptr, std::ref(__call) };
693 template<typename _Ptr_type, typename _Res>
694 struct __future_base::_Task_setter
696 _Ptr_type& _M_result;
697 std::function<_Res()> _M_fn;
699 template<typename _Res, typename... _Args>
700 struct __future_base::_Task_state_base<_Res(_Args...)>
702 template<typename _Alloc>
703 _Task_state_base(const _Alloc& __a)
704 : _M_result(_S_allocate_result<_Res>(__a))
706 typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type;
709 template<typename _Fn, typename _Alloc, typename _Res, typename... _Args>
710 struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final
711 : __future_base::_Task_state_base<_Res(_Args...)>
713 _Task_state(_Fn&& __fn, const _Alloc& __a)
714 : _Task_state_base<_Res(_Args...)>(__a), _M_impl(std::move(__fn), __a)
717 _M_run(_Args... __args)
719 auto __boundfn = std::__bind_simple(std::ref(_M_impl._M_fn),
720 _S_maybe_wrap_ref(std::forward<_Args>(__args))...);
721 auto __setter = _S_task_setter(this->_M_result, std::move(__boundfn));
723 struct _Impl : _Alloc
725 _Impl(_Fn&& __fn, const _Alloc& __a)
726 : _Alloc(__a), _M_fn(std::move(__fn)) {}
730 template<typename _Signature, typename _Fn, typename _Alloc>
731 static shared_ptr<__future_base::_Task_state_base<_Signature>>
732 __create_task_state(_Fn&& __fn, const _Alloc& __a)
734 typedef __future_base::_Task_state<_Fn, _Alloc, _Signature> _State;
735 return std::allocate_shared<_State>(__a, std::move(__fn), __a);
737 template<typename _Task, typename _Fn, bool
738 = is_same<_Task, typename decay<_Fn>::type>::value>
739 struct __constrain_pkgdtask
740 { typedef void __type; };
741 template<typename _Res, typename... _ArgTypes>
742 class packaged_task<_Res(_ArgTypes...)>
744 typedef __future_base::_Task_state_base<_Res(_ArgTypes...)> _State_type;
745 shared_ptr<_State_type> _M_state;
747 template<typename _Fn, typename _Alloc, typename = typename
748 __constrain_pkgdtask<packaged_task, _Fn>::__type>
749 packaged_task(allocator_arg_t, const _Alloc& __a, _Fn&& __fn)
750 : _M_state(__create_task_state<_Res(_ArgTypes...)>(
751 std::forward<_Fn>(__fn), __a))
758 struct SimpleAllocator
760 typedef Tp value_type;
763 SimpleAllocator(const SimpleAllocator<T>& other) ;
766 using std::packaged_task;
767 using std::allocator_arg;
768 __gnu_test::SimpleAllocator<int> a;
769 packaged_task<int()> p(allocator_arg, a, []() { return 1; });