-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[libc++] compile fails when using std::unitialized_copy()
with an output iterator type that has operator!=()
overload
#69334
Comments
This happens because we use a helper type struct __unreachable_sentinel {
template <class _Iter>
friend constexpr bool operator!=(const _Iter&, __unreachable_sentinel) noexcept {
return true;
}
};
template <class _ValueType, class _InputIterator, class _Sentinel1, class _ForwardIterator, class _Sentinel2>
pair<_InputIterator, _ForwardIterator>
__uninitialized_copy(_InputIterator __ifirst, _Sentinel1 __ilast, _ForwardIterator __ofirst, _Sentinel2 __olast) {
_ForwardIterator __idx = __ofirst;
try {
for (; __ifirst != __ilast && __idx != __olast; ++__ifirst, (void)++__idx)
::new (std::__voidify(*__idx)) _ValueType(*__ifirst);
} catch (...) {
std::__destroy(__ofirst, __idx);
throw;
}
return pair<_InputIterator, _ForwardIterator>(std::move(__ifirst), std::move(__idx));
}
template <class _InputIterator, class _ForwardIterator>
_ForwardIterator uninitialized_copy(_InputIterator __ifirst, _InputIterator __ilast, _ForwardIterator __ofirst) {
typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
auto __result = std::__uninitialized_copy<_ValueType>(
std::move(__ifirst), std::move(__ilast), std::move(__ofirst), __unreachable_sentinel());
return std::move(__result.second);
} The goal of this is to reuse the same implementation of |
Wondering, can we make it specialized using SFINAE (std::enable_if) to ensure that it only matches when one of the operands is __unreachable_sentinel? |
…ison operators If an iterator passed to std::uninitialized_copy & friends provided an unconstrained comparison operator, we would trigger an ambiguous overload resolution because we used to compare against __unreachable_sentinel in our implementation. This patch fixes that by only comparing the output iterator when it is actually required, i.e. in the <ranges> versions of the algorithms. Fixes llvm#69334
…ison operators (#69373) If an iterator passed to std::uninitialized_copy & friends provided an unconstrained comparison operator, we would trigger an ambiguous overload resolution because we used to compare against __unreachable_sentinel in our implementation. This patch fixes that by only comparing the output iterator when it is actually required, i.e. in the <ranges> versions of the algorithms. Fixes #69334
Description
When using
std::uninitialized_copy()
from libc++:If the user overloaded
operator!=()
like this:Compilation fails due to ambiguous overload resolution.
Minimal reproducible example
main.cpp
clang console output:
The text was updated successfully, but these errors were encountered: