Commit c89f2d24 by Ville Voutilainen Committed by Ville Voutilainen

Make optional conditionally trivially_{copy,move}_{constructible,assignable}

* include/std/optional (_Optional_payload): Fix the comment in
the class head and turn into a primary and one specialization.
(_Optional_payload::_M_engaged): Strike the NSDMI.
(_Optional_payload<_Tp, false>::operator=(const _Optional_payload&)):
New.
(_Optional_payload<_Tp, false>::operator=(_Optional_payload&&)):
Likewise.
(_Optional_payload<_Tp, false>::_M_get): Likewise.
(_Optional_payload<_Tp, false>::_M_reset): Likewise.
(_Optional_base_impl): Likewise.
(_Optional_base): Turn into a primary and three specializations.
(optional(nullopt)): Change the base init.
* testsuite/20_util/optional/assignment/8.cc: New.
* testsuite/20_util/optional/cons/trivial.cc: Likewise.
* testsuite/20_util/optional/cons/value_neg.cc: Adjust.

From-SVN: r256694
parent 1759d116
2018-01-15 Ville Voutilainen <ville.voutilainen@gmail.com>
Make optional conditionally
trivially_{copy,move}_{constructible,assignable}
* include/std/optional (_Optional_payload): Fix the comment in
the class head and turn into a primary and one specialization.
(_Optional_payload::_M_engaged): Strike the NSDMI.
(_Optional_payload<_Tp, false>::operator=(const _Optional_payload&)):
New.
(_Optional_payload<_Tp, false>::operator=(_Optional_payload&&)):
Likewise.
(_Optional_payload<_Tp, false>::_M_get): Likewise.
(_Optional_payload<_Tp, false>::_M_reset): Likewise.
(_Optional_base_impl): Likewise.
(_Optional_base): Turn into a primary and three specializations.
(optional(nullopt)): Change the base init.
* testsuite/20_util/optional/assignment/8.cc: New.
* testsuite/20_util/optional/cons/trivial.cc: Likewise.
* testsuite/20_util/optional/cons/value_neg.cc: Adjust.
2018-01-15 Jonathan Wakely <jwakely@redhat.com>
PR libstdc++/80276
......
// { dg-options "-std=gnu++17" }
// { dg-do compile }
// Copyright (C) 2018 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/>.
#include <optional>
struct X
{
~X();
};
struct Y
{
Y& operator=(const Y&) = default;
Y& operator=(Y&&);
Y(const Y&) = default;
Y(Y&&) = default;
};
struct Z
{
Z& operator=(const Z&);
Z& operator=(Z&&) = default;
Z(const Z&) = default;
};
struct Y2
{
Y2& operator=(const Y2&) = default;
Y2& operator=(Y2&&);
};
struct Z2
{
Z2& operator=(const Z2&);
Z2& operator=(Z2&&) = default;
};
static_assert(std::is_trivially_copy_assignable_v<std::optional<int>>);
static_assert(std::is_trivially_move_assignable_v<std::optional<int>>);
static_assert(!std::is_trivially_copy_assignable_v<std::optional<X>>);
static_assert(!std::is_trivially_move_assignable_v<std::optional<X>>);
static_assert(std::is_trivially_copy_assignable_v<std::optional<Y>>);
static_assert(!std::is_trivially_move_assignable_v<std::optional<Y>>);
static_assert(!std::is_trivially_copy_assignable_v<std::optional<Z>>);
static_assert(std::is_trivially_move_assignable_v<std::optional<Z>>);
static_assert(std::is_trivially_copy_assignable_v<Y2>);
static_assert(!std::is_trivially_move_assignable_v<Y2>);
static_assert(!std::is_trivially_copy_assignable_v<std::optional<Y2>>);
static_assert(!std::is_trivially_move_assignable_v<std::optional<Y2>>);
static_assert(!std::is_trivially_copy_assignable_v<Z2>);
static_assert(std::is_trivially_move_assignable_v<Z2>);
static_assert(!std::is_trivially_copy_assignable_v<std::optional<Z2>>);
static_assert(!std::is_trivially_move_assignable_v<std::optional<Z2>>);
struct S {
S(const S&&) = delete;
S& operator=(const S&) = default;
};
static_assert(std::is_trivially_copy_assignable_v<S>);
union U {
char dummy;
S s;
};
static_assert(std::is_trivially_copy_assignable_v<U>);
static_assert(!std::is_trivially_copy_assignable_v<std::optional<S>>);
static_assert(!std::is_copy_assignable_v<std::optional<S>>);
struct S2 {
S2(S2&&) = delete;
S2& operator=(const S2&) = default;
};
static_assert(std::is_trivially_move_assignable_v<S2>);
union U2 {
char dummy;
S2 s;
};
static_assert(std::is_trivially_move_assignable_v<U2>);
static_assert(!std::is_trivially_move_assignable_v<std::optional<S2>>);
static_assert(!std::is_move_assignable_v<std::optional<S2>>);
// { dg-options "-std=gnu++17" }
// { dg-do compile }
// Copyright (C) 2018 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/>.
#include <optional>
struct X
{
~X();
};
struct Y
{
Y(const Y&) = default;
Y(Y&&);
};
struct Z
{
Z(const Z&);
Z(Z&&) = default;
};
static_assert(std::is_trivially_copy_constructible_v<std::optional<int>>);
static_assert(std::is_trivially_move_constructible_v<std::optional<int>>);
static_assert(!std::is_trivially_copy_constructible_v<std::optional<X>>);
static_assert(!std::is_trivially_move_constructible_v<std::optional<X>>);
static_assert(std::is_trivially_copy_constructible_v<std::optional<Y>>);
static_assert(!std::is_trivially_move_constructible_v<std::optional<Y>>);
static_assert(!std::is_trivially_copy_constructible_v<std::optional<Z>>);
static_assert(std::is_trivially_move_constructible_v<std::optional<Z>>);
......@@ -37,8 +37,8 @@ int main()
std::optional<std::unique_ptr<int>> oup2 = new int; // { dg-error "conversion" }
struct U { explicit U(std::in_place_t); };
std::optional<U> ou(std::in_place); // { dg-error "no matching" }
// { dg-error "no type" "" { target { *-*-* } } 495 }
// { dg-error "no type" "" { target { *-*-* } } 505 }
// { dg-error "no type" "" { target { *-*-* } } 562 }
// { dg-error "no type" "" { target { *-*-* } } 647 }
// { dg-error "no type" "" { target { *-*-* } } 657 }
// { dg-error "no type" "" { target { *-*-* } } 714 }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment