namespace __detail
{
+ template<class _From, class _To>
+ concept __convertible_to_non_slicing = convertible_to<_From, _To>
+ && !(is_pointer_v<decay_t<_From>> && is_pointer_v<decay_t<_To>>
+ && __not_same_as<remove_pointer_t<decay_t<_From>>,
+ remove_pointer_t<decay_t<_To>>>);
+
template<typename _Tp>
concept __pair_like
= !is_reference_v<_Tp> && requires(_Tp __t)
{ get<1>(__t) } -> convertible_to<const tuple_element_t<1, _Tp>&>;
};
- template<typename _Tp, typename _Up, typename _Vp>
- concept __pair_like_convertible_to
- = !range<_Tp> && __pair_like<remove_reference_t<_Tp>>
- && requires(_Tp&& __t)
- {
- { get<0>(std::forward<_Tp>(__t)) } -> convertible_to<_Up>;
- { get<1>(std::forward<_Tp>(__t)) } -> convertible_to<_Vp>;
- };
-
template<typename _Tp, typename _Up, typename _Vp>
concept __pair_like_convertible_from
= !range<_Tp> && __pair_like<_Tp>
- && constructible_from<_Tp, _Up, _Vp>;
+ && constructible_from<_Tp, _Up, _Vp>
+ && __convertible_to_non_slicing<_Up, tuple_element_t<0, _Tp>>
+ && convertible_to<_Vp, tuple_element_t<1, _Tp>>;
template<typename _Tp>
concept __iterator_sentinel_pair
subrange() = default;
constexpr
- subrange(_It __i, _Sent __s) requires (!_S_store_size)
+ subrange(__detail::__convertible_to_non_slicing<_It> auto __i, _Sent __s)
+ requires (!_S_store_size)
: _M_begin(std::move(__i)), _M_end(__s)
{ }
constexpr
- subrange(_It __i, _Sent __s,
+ subrange(__detail::__convertible_to_non_slicing<_It> auto __i, _Sent __s,
__detail::__make_unsigned_like_t<iter_difference_t<_It>> __n)
requires (_Kind == subrange_kind::sized)
: _M_begin(std::move(__i)), _M_end(__s)
template<__detail::__not_same_as<subrange> _Rng>
requires borrowed_range<_Rng>
- && convertible_to<iterator_t<_Rng>, _It>
+ && __detail::__convertible_to_non_slicing<iterator_t<_Rng>, _It>
&& convertible_to<sentinel_t<_Rng>, _Sent>
constexpr
subrange(_Rng&& __r) requires (!_S_store_size || sized_range<_Rng>)
}
template<borrowed_range _Rng>
- requires convertible_to<iterator_t<_Rng>, _It>
+ requires __detail::__convertible_to_non_slicing<iterator_t<_Rng>, _It>
&& convertible_to<sentinel_t<_Rng>, _Sent>
constexpr
subrange(_Rng&& __r,
: subrange{ranges::begin(__r), ranges::end(__r), __n}
{ }
- template<__detail::__not_same_as<subrange> _PairLike>
- requires __detail::__pair_like_convertible_to<_PairLike, _It, _Sent>
- constexpr
- subrange(_PairLike&& __r) requires (!_S_store_size)
- : subrange{std::get<0>(std::forward<_PairLike>(__r)),
- std::get<1>(std::forward<_PairLike>(__r))}
- { }
-
- template<__detail::__pair_like_convertible_to<_It, _Sent> _PairLike>
- constexpr
- subrange(_PairLike&& __r,
- __detail::__make_unsigned_like_t<iter_difference_t<_It>> __n)
- requires (_Kind == subrange_kind::sized)
- : subrange{std::get<0>(std::forward<_PairLike>(__r)),
- std::get<1>(std::forward<_PairLike>(__r)), __n}
- { }
-
template<__detail::__not_same_as<subrange> _PairLike>
requires __detail::__pair_like_convertible_from<_PairLike, const _It&,
const _Sent&>
}
};
+ template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
+ subrange(_It, _Sent) -> subrange<_It, _Sent>;
+
template<input_or_output_iterator _It, sentinel_for<_It> _Sent>
subrange(_It, _Sent,
__detail::__make_unsigned_like_t<iter_difference_t<_It>>)
--- /dev/null
+// Copyright (C) 2020 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+#include <ranges>
+
+using std::ranges::subrange;
+
+// LWG 3282. subrange converting constructor should disallow derived to base
+// conversions
+
+struct Base {};
+struct Derived : Base {};
+subrange<Derived*> sd;
+subrange<Base*> sb = sd; // { dg-error "conversion" }