diff options
| author | William A. Kennington III <wak@google.com> | 2019-11-05 17:28:58 -0800 |
|---|---|---|
| committer | William A. Kennington III <wak@google.com> | 2019-11-05 17:29:05 -0800 |
| commit | f1c46f813fed48f18c4f846d597df5e87a91b5d0 (patch) | |
| tree | 12c1b9fc7c54630735f9ee63e07bf04be1232c0b /src | |
| parent | 4ef36e7904aa354256ab5818c543df0a9c61f90f (diff) | |
| download | stdplus-f1c46f813fed48f18c4f846d597df5e87a91b5d0.tar.gz stdplus-f1c46f813fed48f18c4f846d597df5e87a91b5d0.zip | |
handle: Cleanup noexcept guarantees
Some of our noexcept guarantees were just wrong, and we weren't
providing it for the move constructor when possible.
Change-Id: I48452a4f07655d7cc479ca8ab8d744a59c119459
Signed-off-by: William A. Kennington III <wak@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/stdplus/handle/copyable.hpp | 12 | ||||
| -rw-r--r-- | src/stdplus/handle/managed.hpp | 16 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/stdplus/handle/copyable.hpp b/src/stdplus/handle/copyable.hpp index df383db..ef93263 100644 --- a/src/stdplus/handle/copyable.hpp +++ b/src/stdplus/handle/copyable.hpp @@ -1,6 +1,7 @@ #pragma once #include <optional> #include <stdplus/handle/managed.hpp> +#include <type_traits> #include <utility> namespace stdplus @@ -40,13 +41,12 @@ struct Copyable * @param[in] maybeV - Maybe the object being managed */ template <typename... Vs> - constexpr explicit Handle(std::optional<T>&& maybeV, - Vs&&... vs) noexcept : + constexpr explicit Handle(std::optional<T>&& maybeV, Vs&&... vs) : MHandle(std::move(maybeV), std::forward<Vs>(vs)...) { } template <typename... Vs> - constexpr explicit Handle(T&& maybeV, Vs&&... vs) noexcept : + constexpr explicit Handle(T&& maybeV, Vs&&... vs) : MHandle(std::move(maybeV), std::forward<Vs>(vs)...) { } @@ -56,7 +56,9 @@ struct Copyable reset(other.maybe_value()); } - constexpr Handle(Handle&& other) noexcept : MHandle(std::move(other)) + constexpr Handle(Handle&& other) noexcept( + std::is_nothrow_move_constructible_v<MHandle>) : + MHandle(std::move(other)) { } @@ -71,7 +73,7 @@ struct Copyable return *this; } - constexpr Handle& operator=(Handle&& other) noexcept + constexpr Handle& operator=(Handle&& other) { MHandle::operator=(std::move(other)); return *this; diff --git a/src/stdplus/handle/managed.hpp b/src/stdplus/handle/managed.hpp index de6a9f1..94c0bfa 100644 --- a/src/stdplus/handle/managed.hpp +++ b/src/stdplus/handle/managed.hpp @@ -2,6 +2,7 @@ #include <cstdlib> #include <optional> #include <tuple> +#include <type_traits> #include <utility> namespace stdplus @@ -37,14 +38,12 @@ struct Managed * @param[in] maybeV - Maybe the object being managed */ template <typename... Vs> - constexpr explicit Handle(std::optional<T>&& maybeV, - Vs&&... vs) noexcept : - as(std::forward<Vs>(vs)...), - maybeT(std::move(maybeV)) + constexpr explicit Handle(std::optional<T>&& maybeV, Vs&&... vs) : + as(std::forward<Vs>(vs)...), maybeT(std::move(maybeV)) { } template <typename... Vs> - constexpr explicit Handle(T&& maybeV, Vs&&... vs) noexcept : + constexpr explicit Handle(T&& maybeV, Vs&&... vs) : as(std::forward<Vs>(vs)...), maybeT(std::move(maybeV)) { } @@ -52,8 +51,11 @@ struct Managed Handle(const Handle& other) = delete; Handle& operator=(const Handle& other) = delete; - constexpr Handle(Handle&& other) : - as(std::move(other.as)), maybeT(std::move(other.maybeT)) + constexpr Handle(Handle&& other) noexcept( + std::is_nothrow_move_constructible_v<std::tuple<As...>>&& + std::is_nothrow_move_constructible_v<std::optional<T>>) : + as(std::move(other.as)), + maybeT(std::move(other.maybeT)) { other.maybeT = std::nullopt; } |

