From 7c083b0856f29c13b91e12c6212180d0545a3a9c Mon Sep 17 00:00:00 2001 From: Avani Nandini Date: Tue, 29 Oct 2013 00:11:49 -0700 Subject: [PATCH] make move-ctor and destructor noexcept for folly::Optional Summary: as per summary @override-unit-failures Test Plan: run unit tests Reviewed By: delong.j@fb.com FB internal diff: D1031726 --- folly/Optional.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/folly/Optional.h b/folly/Optional.h index 4295e271..f0d21c98 100644 --- a/folly/Optional.h +++ b/folly/Optional.h @@ -91,7 +91,9 @@ class Optional { : hasValue_(false) { } - Optional(const Optional& src) { + Optional(const Optional& src) + noexcept(std::is_nothrow_copy_constructible::value) { + if (src.hasValue()) { construct(src.value()); } else { @@ -99,7 +101,9 @@ class Optional { } } - Optional(Optional&& src) { + Optional(Optional&& src) + noexcept(std::is_nothrow_move_constructible::value) { + if (src.hasValue()) { construct(std::move(src.value())); src.clear(); @@ -120,7 +124,7 @@ class Optional { construct(newValue); } - ~Optional() { + ~Optional() noexcept { clear(); } @@ -167,12 +171,16 @@ class Optional { return *this; } - Optional& operator=(Optional &&other) { + Optional& operator=(Optional &&other) + noexcept (std::is_nothrow_move_assignable::value) { + assign(std::move(other)); return *this; } - Optional& operator=(const Optional &other) { + Optional& operator=(const Optional &other) + noexcept (std::is_nothrow_copy_assignable::value) { + assign(other); return *this; } -- 2.34.1