From 820333dce47d8b961927640df056072bc0ff3eb0 Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Tue, 9 Jul 2019 14:54:49 -0700 Subject: [PATCH] Add noexcept to missing places in expected.h These move and assignment operations are conditionally noexcept, so add that to their definitions. This is a performance issue as well as correctness, since std containers will copy instead of move during resize if these operations are not noexcept. Test: build Change-Id: I148f7eb3489e7f1dd68cc0fb0e555b56470e42da --- base/include/android-base/expected.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/base/include/android-base/expected.h b/base/include/android-base/expected.h index 6153b7766..030ef35e5 100644 --- a/base/include/android-base/expected.h +++ b/base/include/android-base/expected.h @@ -256,7 +256,8 @@ class _NODISCARD_ expected { expected& operator=(const expected& rhs) = default; // Note for SFNAIE above applies to here as well - expected& operator=(expected&& rhs) = default; + expected& operator=(expected&& rhs) noexcept( + std::is_nothrow_move_assignable_v&& std::is_nothrow_move_assignable_v) = default; template && @@ -542,7 +543,7 @@ class _NODISCARD_ expected { expected& operator=(const expected& rhs) = default; // Note for SFNAIE above applies to here as well - expected& operator=(expected&& rhs) = default; + expected& operator=(expected&& rhs) noexcept(std::is_nothrow_move_assignable_v) = default; template expected& operator=(const unexpected& rhs) { @@ -633,7 +634,7 @@ class unexpected { public: // constructors constexpr unexpected(const unexpected&) = default; - constexpr unexpected(unexpected&&) = default; + constexpr unexpected(unexpected&&) noexcept(std::is_nothrow_move_constructible_v) = default; template && @@ -709,7 +710,8 @@ class unexpected { // assignment constexpr unexpected& operator=(const unexpected&) = default; - constexpr unexpected& operator=(unexpected&&) = default; + constexpr unexpected& operator=(unexpected&&) noexcept(std::is_nothrow_move_assignable_v) = + default; template constexpr unexpected& operator=(const unexpected& rhs) { val_ = rhs.value();