]> git.ipfire.org Git - thirdparty/gcc.git/commit
Fix condition for std::variant to be copy constructible
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Apr 2019 19:27:27 +0000 (19:27 +0000)
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 17 Apr 2019 19:27:27 +0000 (19:27 +0000)
commit37a7dbf97e65374610363d3efe289dc177955f1a
treeb9c620ef77a1d247c02bf749316317648c4f6c99
parente9a490a489dfe17582bcef117c73d3e5d7c2eae3
Fix condition for std::variant to be copy constructible

The standard says the std::variant copy constructor is defined as
deleted unless all alternative types are copy constructible, but we were
making it also depend on move constructible. Fix the condition and
enhance the tests to check the semantics with pathological copy-only
types (i.e. supporting copying but having deleted moves).

The enhanced tests revealed a regression in copy assignment for
non-trivial alternative types, where the assignment would not be
performed because the condition in the _Copy_assign_base visitor is
false: is_same_v<remove_reference_t<T&>, remove_reference_t<const T&>>.

* include/std/variant (__detail::__variant::_Traits::_S_copy_assign):
Do not depend on whether all alternative types are move constructible.
(__detail::__variant::_Copy_assign_base::operator=): Remove cv-quals
from the operand when deciding whether to perform the assignment.
* testsuite/20_util/variant/compile.cc (DeletedMoves): Define type
with deleted move constructor and deleted move assignment operator.
(default_ctor, copy_ctor, move_ctor, copy_assign, move_assign): Check
behaviour of variants with DeletedMoves as an alternative.
* testsuite/20_util/variant/run.cc (DeletedMoves): Define same type.
(move_ctor, move_assign): Check that moving a variant with a
DeletedMoves alternative falls back to copying instead of moving.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@270425 138bc75d-0d04-0410-961f-82ee72b054a4
libstdc++-v3/ChangeLog
libstdc++-v3/include/std/variant
libstdc++-v3/testsuite/20_util/variant/compile.cc
libstdc++-v3/testsuite/20_util/variant/run.cc