| 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 |
} // namespace |
| 15 |
inline namespace __1 { |
| 16 |
template <class _Tp> |
| 17 |
using __libcpp_remove_reference_t = __remove_reference_t(_Tp); |
| 18 |
template <bool, class _IfRes, class> using conditional_t = _IfRes; |
| 19 |
template <class _Tp, class _Up> |
| 20 |
using _IsSame = _BoolConstant<__is_same(_Tp, _Up)>; |
| 21 |
template <class _Tp> struct enable_if { |
| 22 |
typedef _Tp type; |
| 23 |
}; |
| 24 |
template <bool, class _Tp = void> using __enable_if_t = _Tp; |
| 25 |
template <class _Bp, class _Dp> |
| 26 |
constexpr bool is_base_of_v = __is_base_of(_Bp, _Dp); |
| 27 |
template <class _Tp> _Tp __declval(long); |
| 28 |
template <class _Tp> decltype(__declval<_Tp>(0)) declval(); |
| 29 |
template <class _Fp, class... _Args> |
| 30 |
constexpr decltype(declval<_Fp>()(declval<_Args>()...)) |
| 31 |
__invoke(_Fp __f, _Args... __args) { |
| 32 |
return (__f)((__args)...); |
| 33 |
} |
| 34 |
template <class, class _Fp, class... _Args> struct __invokable_r { |
| 35 |
template <class _XFp, class... _XArgs> |
| 36 |
static decltype(__invoke(declval<_XFp>(), declval<_XArgs>()...)) |
| 37 |
__try_call(int); |
| 38 |
using _Result = decltype(__try_call<_Fp, _Args...>(0)); |
| 39 |
}; |
| 40 |
template <class _Func, class... _Args> |
| 41 |
struct __invoke_result |
| 42 |
: enable_if<typename __invokable_r<void, _Func, _Args...>::_Result> {}; |
| 43 |
template <class _Fn, class... _Args> |
| 44 |
using invoke_result_t = __invoke_result<_Fn, _Args...>::type; |
| 45 |
template <class _Tp> constexpr __libcpp_remove_reference_t<_Tp> &&move(_Tp &&); |
| 46 |
template <class _From, class _To> |
| 47 |
constexpr bool is_convertible_v = __is_convertible(_From, _To); |
| 48 |
template <class _From, class _To> |
| 49 |
concept convertible_to = |
| 50 |
is_convertible_v<_From, _To> && requires { (declval<_From>()); }; |
| 51 |
template <class _Tp, class _Up> |
| 52 |
concept __same_as_impl = _IsSame<_Tp, _Up>::value; |
| 53 |
template <class _Tp, class _Up> |
| 54 |
concept same_as = __same_as_impl<_Tp, _Up> && __same_as_impl<_Up, _Tp>; |
| 55 |
template <class _Tp> using __remove_cvref_t = __remove_cvref(_Tp); |
| 56 |
template <class _Tp> using remove_cvref_t = __remove_cvref_t<_Tp>; |
| 57 |
template <class _Xp, class _Yp> |
| 58 |
using __cond_res = |
| 59 |
decltype(false ? declval<_Xp (&)()>()() : declval<_Yp (&)()>()()); |
| 60 |
template <class...> struct common_reference; |
| 61 |
template <class... _Types> |
| 62 |
using common_reference_t = common_reference<_Types...>::type; |
| 63 |
template <class, class> struct __common_reference_sub_bullet3; |
| 64 |
template <class _Tp, class _Up> |
| 65 |
struct common_reference<_Tp, _Up> : __common_reference_sub_bullet3<_Tp, _Up> {}; |
| 66 |
template <class _Tp, class _Up> |
| 67 |
requires requires { typename __cond_res<_Tp, _Up>; } |
| 68 |
struct __common_reference_sub_bullet3<_Tp, _Up> { |
| 69 |
using type = __cond_res<_Tp, _Up>; |
| 70 |
}; |
| 71 |
template <class _Tp, class _Up> |
| 72 |
concept common_reference_with = |
| 73 |
same_as<common_reference_t<_Tp, _Up>, common_reference_t<_Up, _Tp>> && |
| 74 |
convertible_to<_Tp, common_reference_t<_Tp, _Up>> && |
| 75 |
convertible_to<_Up, common_reference_t<_Tp, _Up>>; |
| 76 |
template <class _Tp> |
| 77 |
using __make_const_lvalue_ref = __libcpp_remove_reference_t<_Tp>; |
| 78 |
template <class _Lhs, class _Rhs> |
| 79 |
concept assignable_from = |
| 80 |
common_reference_with<__make_const_lvalue_ref<_Lhs>, |
| 81 |
__make_const_lvalue_ref<_Rhs>> && |
| 82 |
requires(_Lhs __lhs, _Rhs __rhs) { |
| 83 |
{ __lhs = (__rhs) }; |
| 84 |
}; |
| 85 |
template <class _Tp> |
| 86 |
concept default_initializable = requires { _Tp{}; }; |
| 87 |
template <class _Tp> constexpr bool is_object_v = __is_object(_Tp); |
| 88 |
template <class _Dp, class _Bp> |
| 89 |
concept derived_from = is_base_of_v<_Bp, _Dp> && is_convertible_v<_Dp *, _Bp *>; |
| 90 |
template <class _Tp, class _Up> |
| 91 |
concept __weakly_equality_comparable_with = requires( |
| 92 |
__make_const_lvalue_ref<_Tp> __t, __make_const_lvalue_ref<_Up> __u) { |
| 93 |
{ __u }; |
| 94 |
}; |
| 95 |
template <class _Fn, class... _Args> |
| 96 |
constexpr invoke_result_t<_Fn, _Args...> invoke(_Fn __f, _Args &&...__args) { |
| 97 |
return __invoke((__f), (__args)...); |
| 98 |
} |
| 99 |
template <class _Fn, class... _Args> |
| 100 |
concept invocable = |
| 101 |
requires(_Fn __fn, _Args... __args) { invoke((__fn), (__args)...); }; |
| 102 |
template <class _Fn, class... _Args> |
| 103 |
concept regular_invocable = invocable<_Fn, _Args...>; |
| 104 |
template <template <class> class, class> |
| 105 |
integral_constant<bool, false> __sfinae_test_impl(); |
| 106 |
template <template <class> class _Templ, class... _Args> |
| 107 |
using _IsValidExpansion = decltype(__sfinae_test_impl<_Templ, _Args...>()); |
| 108 |
template <class _Tp> |
| 109 |
using __test_for_primary_template = |
| 110 |
__enable_if_t<_IsSame<_Tp, typename _Tp::__primary_template>::value>; |
| 111 |
template <class _Tp> |
| 112 |
using __is_primary_template = |
| 113 |
_IsValidExpansion<__test_for_primary_template, _Tp>; |
| 114 |
template <class> struct __cond_value_type; |
| 115 |
template <class _Tp> |
| 116 |
requires is_object_v<_Tp> |
| 117 |
struct __cond_value_type<_Tp> { |
| 118 |
using value_type = remove_cv_t<_Tp>; |
| 119 |
}; |
| 120 |
template <class _Tp> |
| 121 |
concept __has_member_value_type = requires { typename _Tp; }; |
| 122 |
template <class> struct indirectly_readable_traits; |
| 123 |
template <class _Tp> |
| 124 |
struct indirectly_readable_traits<_Tp *> : __cond_value_type<_Tp> {}; |
| 125 |
template <__has_member_value_type _Tp> |
| 126 |
struct indirectly_readable_traits<_Tp> |
| 127 |
: __cond_value_type<typename _Tp::value_type> {}; |
| 128 |
template <bool> struct _OrImpl; |
| 129 |
template <> struct _OrImpl<true> { |
| 130 |
template <class, class _First, class... _Rest> |
| 131 |
using _Result = |
| 132 |
_OrImpl<!bool() && sizeof...(_Rest)>::template _Result<_First, _Rest...>; |
| 133 |
}; |
| 134 |
template <> struct _OrImpl<false> { |
| 135 |
template <class _Res> using _Result = _Res; |
| 136 |
}; |
| 137 |
template <class... _Args> |
| 138 |
using _Or = |
| 139 |
_OrImpl<sizeof...(_Args) != |
| 140 |
0>::template _Result<integral_constant<bool, false>, _Args...>; |
| 141 |
template <class _Tp> |
| 142 |
concept __dereferenceable = requires(_Tp __t) { |
| 143 |
{ __t }; |
| 144 |
}; |
| 145 |
template <__dereferenceable _Tp> |
| 146 |
using iter_reference_t = decltype(*declval<_Tp>()); |
| 147 |
struct input_iterator_tag {}; |
| 148 |
struct forward_iterator_tag : input_iterator_tag {}; |
| 149 |
struct bidirectional_iterator_tag : forward_iterator_tag {}; |
| 150 |
struct __iter_concept_random_fallback { |
| 151 |
template <class> |
| 152 |
using _Apply = __enable_if_t<__is_primary_template<int>::value, |
| 153 |
bidirectional_iterator_tag>; |
| 154 |
}; |
| 155 |
template <class _Tester> struct __test_iter_concept : _Tester {}; |
| 156 |
struct __iter_concept_cache { |
| 157 |
using type = _Or<__test_iter_concept<__iter_concept_random_fallback>>; |
| 158 |
}; |
| 159 |
template <class _Iter> |
| 160 |
using _ITER_CONCEPT = __iter_concept_cache::type::_Apply<_Iter>; |
| 161 |
template <class _Ip> |
| 162 |
using iter_value_t = |
| 163 |
conditional_t<__is_primary_template<int>::value, |
| 164 |
indirectly_readable_traits<remove_cvref_t<_Ip>>, |
| 165 |
int>::value_type; |
| 166 |
namespace ranges { |
| 167 |
struct Trans_NS___iter_move___fn { |
| 168 |
template <class _Ip> auto operator()(_Ip __i) const -> decltype(std::move(*(__i))); |
| 169 |
}; |
| 170 |
inline namespace { |
| 171 |
auto iter_move = Trans_NS___iter_move___fn{}; |
| 172 |
} |
| 173 |
} // namespace ranges |
| 174 |
template <__dereferenceable _Tp> |
| 175 |
requires requires { |
| 176 |
{ ranges::iter_move }; |
| 177 |
} |
| 178 |
using iter_rvalue_reference_t = decltype(ranges::iter_move(declval<_Tp>())); |
| 179 |
template <class _In> |
| 180 |
concept __indirectly_readable_impl = |
| 181 |
requires(_In __i) { |
| 182 |
{ ranges::iter_move(__i) } -> same_as<iter_rvalue_reference_t<_In>>; |
| 183 |
} && common_reference_with<iter_reference_t<_In>, iter_value_t<_In>> && |
| 184 |
common_reference_with<iter_reference_t<_In>, |
| 185 |
iter_rvalue_reference_t<_In>> && |
| 186 |
common_reference_with<iter_rvalue_reference_t<_In>, iter_value_t<_In>>; |
| 187 |
template <class _In> |
| 188 |
concept indirectly_readable = __indirectly_readable_impl<remove_cvref_t<_In>>; |
| 189 |
template <class _Tp> struct __indirect_value_t_impl { |
| 190 |
using type = iter_value_t<_Tp>; |
| 191 |
}; |
| 192 |
template <indirectly_readable _Tp> |
| 193 |
using __indirect_value_t = __indirect_value_t_impl<_Tp>::type; |
| 194 |
template <class _Sp, class _Ip> |
| 195 |
concept sentinel_for = __weakly_equality_comparable_with<_Sp, _Ip>; |
| 196 |
template <class _Ip> |
| 197 |
concept input_iterator = requires { typename _ITER_CONCEPT<_Ip>; } && |
| 198 |
derived_from<_ITER_CONCEPT<_Ip>, input_iterator_tag>; |
| 199 |
template <class _Fp, class _It> |
| 200 |
concept indirectly_unary_invocable = |
| 201 |
invocable<_Fp, __indirect_value_t<_It>> && |
| 202 |
invocable<_Fp, iter_reference_t<_It>> && |
| 203 |
common_reference_with<invoke_result_t<_Fp, __indirect_value_t<_It>>, |
| 204 |
invoke_result_t<_Fp, iter_reference_t<_It>>>; |
| 205 |
template <class _Fp, class _It> |
| 206 |
concept indirectly_regular_unary_invocable = |
| 207 |
regular_invocable<_Fp, __indirect_value_t<_It>> && |
| 208 |
regular_invocable<_Fp, iter_reference_t<_It>> && |
| 209 |
common_reference_with<invoke_result_t<_Fp, __indirect_value_t<_It>>, |
| 210 |
invoke_result_t<_Fp, iter_reference_t<_It>>>; |
| 211 |
template <class _Fp, class... _Its> |
| 212 |
requires(indirectly_readable<_Its> && ...) && |
| 213 |
invocable<_Fp, iter_reference_t<_Its>...> |
| 214 |
using indirect_result_t = invoke_result_t<_Fp, iter_reference_t<_Its>...>; |
| 215 |
template <class _It, class _Proj> struct __projected_impl { |
| 216 |
struct __type { |
| 217 |
using value_type = remove_cvref_t<indirect_result_t<_Proj, _It>>; |
| 218 |
indirect_result_t<_Proj, _It> operator*(); |
| 219 |
}; |
| 220 |
}; |
| 221 |
template <indirectly_readable _It, |
| 222 |
indirectly_regular_unary_invocable<_It> _Proj> |
| 223 |
using projected = __projected_impl<_It, _Proj>::__type; |
| 224 |
namespace ranges { |
| 225 |
template <class, class> using for_each_result = int; |
| 226 |
|
| 227 |
struct Z {}; |
| 228 |
constexpr Z zomg() { |
| 229 |
return {}; |
| 230 |
} |
| 231 |
constexpr Z zomg2(Z z) { |
| 232 |
return {}; |
| 233 |
} |
| 234 |
|
| 235 |
struct __for_each { |
| 236 |
|
| 237 |
template <input_iterator _Iter, sentinel_for<_Iter> _Sent, class _Proj, |
| 238 |
indirectly_unary_invocable<projected<_Iter, _Proj>> _Func> |
| 239 |
constexpr for_each_result<_Iter, _Func> |
| 240 |
operator()(_Iter __first, _Sent __last, _Func __func, _Proj __proj) const { |
| 241 |
|
| 242 |
for (; __first != __last; ++__first) |
| 243 |
invoke(__func, invoke(__proj, *__first)); |
| 244 |
return {}; |
| 245 |
} |
| 246 |
|
| 247 |
}; |
| 248 |
inline namespace { |
| 249 |
auto for_each = __for_each{}; |
| 250 |
} |
| 251 |
} // namespace ranges |
| 252 |
} // namespace __1 |
| 253 |
} // namespace std |
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
struct T {}; |
| 258 |
struct Proj { |
| 259 |
constexpr void *operator()(T) { return nullptr; } |
| 260 |
}; |
| 261 |
struct UnaryVoid { |
| 262 |
constexpr void operator()(void *) {} |
| 263 |
}; |
| 264 |
|
| 265 |
constexpr bool all_the_algorithms() { |
| 266 |
T a[2]; |
| 267 |
T *last = a + 2; |
| 268 |
std::ranges::for_each(a, last, UnaryVoid(), Proj()); |
| 269 |
return true; |
| 270 |
} |
| 271 |
static_assert(all_the_algorithms()); |