aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-01-06 20:52:34 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2019-01-06 20:52:34 +0000
commitcaf80d87b53402b64eee8bba2cf5b036c43bf60b (patch)
treef24b48f30f75133c6feccb12ea6e56b6481a0cc2 /gcc
parentbe917808aa3310d46f586e6586ef08d302837f1e (diff)
downloadgcc-caf80d87b53402b64eee8bba2cf5b036c43bf60b.zip
gcc-caf80d87b53402b64eee8bba2cf5b036c43bf60b.tar.gz
gcc-caf80d87b53402b64eee8bba2cf5b036c43bf60b.tar.bz2
PR libstdc++/87431 fix regression introduced by r264574
The previous patch for PR 87431 assumed that initialing a scalar type could not throw, but it can obtain its value via a conversion operator, which could throw. This meant the variant could get into a valueless state, but the valueless_by_exception() member function would always return false. This patch fixes it by changing the emplace members to have strong exception safety when initializing a contained value of trivially copyable type. The _M_valid() member gets a corresponding change to always return true for trivially copyable types, not just scalar types. Strong exception safety (i.e. never becoming valueless) is achieved by only replacing the current contained value once any potentially throwing operations have completed. If constructing the new contained value can throw then a new std::variant object is constructed to hold it, and then move-assigned to *this (which won't throw). PR libstdc++/87431 * include/std/variant (_Variant_storage<true, _Types...>::_M_valid): Check is_trivially_copyable instead of is_scalar. (variant::emplace<N, Args>(Args&&...)): If construction of the new contained value can throw and its type is trivially copyable then construct into a temporary variant and move from it, to provide the strong exception safety guarantee. (variant::emplace<N, U, Args>(initializer_list<U>, Args&&...)): Likewise. * testsuite/20_util/variant/87431.cc: New test. * testsuite/20_util/variant/run.cc: Adjust test so that throwing conversion causes valueless state. From-SVN: r267614
Diffstat (limited to 'gcc')
0 files changed, 0 insertions, 0 deletions