[Bug libstdc++/83981] vector::resize(size_type) should not require T to be CopyInsertable when std=c++14
dtrebbien at gmail dot com
gcc-bugzilla@gcc.gnu.org
Fri Jan 26 00:25:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83981
--- Comment #12 from Daniel Trebbien <dtrebbien at gmail dot com> ---
https://wg21.link/lwg2158 looks relevant, particularly this part:
"This requirement is not sufficient if an implementation is free to select copy
constructor when !is_nothrow_move_constructible<T>::value &&
is_copy_constructible<T>::value evaluates to true. Unfortunately,
is_copy_constructible cannot reliably determine whether T is really
copy-constructible. A class may contain public non-deleted copy constructor
whose definition does not exist or cannot be instantiated successfully (e.g.,
std::vector<std::unique_ptr<int>> has copy constructor, but this type is not
copy-constructible)."
Even though is_copy_constructible for std::vector<std::unique_ptr<...>> is
true, resizing a vector of this element type works because the std::vector move
constructor is noexcept, so the move constructor is selected.
Jonathan, I personally think that your argument in Comment 10 is persuasive.
Further, I like the suggestion in LWG 2158 to add "if
!is_nothrow_move_constructible<T>::value && is_copy_constructible<T>::value
then T shall be CopyInsertable into *this;" to the requirements of
vector::resize(size_type). I think that this would be required because, based
on my reading of [temp.inst], it is a well-formed program to instantiate
boost::optional<NonCopyConstructibleType>, as this does not require the
instantiation of the boost::optional<NonCopyConstructibleType> copy
constructor.
More information about the Gcc-bugs
mailing list