Make Optional nothrow_default_constructible
authorStepan Palamarchuk <stepan@fb.com>
Wed, 11 Nov 2015 22:22:01 +0000 (14:22 -0800)
committerfacebook-github-bot-1 <folly-bot@fb.com>
Wed, 11 Nov 2015 23:20:21 +0000 (15:20 -0800)
Summary: It never throws.

Reviewed By: pavlo-fb

Differential Revision: D2640886

fb-gh-sync-id: cd643f8847f4bf5619415731484f91fb07116784

folly/Optional.h
folly/test/OptionalTest.cpp

index def3670f00ab69946c0fce6eb12441eebd4466dd..84f5d4439ea1300efda80d342ff5b35009dade31 100644 (file)
@@ -96,7 +96,7 @@ class Optional {
   static_assert(!std::is_abstract<Value>::value,
                 "Optional may not be used with abstract types");
 
   static_assert(!std::is_abstract<Value>::value,
                 "Optional may not be used with abstract types");
 
-  Optional()
+  Optional() noexcept
     : hasValue_(false) {
   }
 
     : hasValue_(false) {
   }
 
index 42fd4926808156978f27a07c0425546fa492e85c..0c3d9fdc95b2375fc26c52a64c70d7e82877bf92 100644 (file)
@@ -21,6 +21,7 @@
 #include <algorithm>
 #include <iomanip>
 #include <string>
 #include <algorithm>
 #include <iomanip>
 #include <string>
+#include <type_traits>
 
 #include <glog/logging.h>
 #include <gtest/gtest.h>
 
 #include <glog/logging.h>
 #include <gtest/gtest.h>
@@ -542,4 +543,8 @@ TEST(Optional, Exceptions) {
   EXPECT_THROW(empty.value(), OptionalEmptyException);
 }
 
   EXPECT_THROW(empty.value(), OptionalEmptyException);
 }
 
+TEST(Optional, NoThrowDefaultConstructible) {
+  EXPECT_TRUE(std::is_nothrow_default_constructible<Optional<bool>>::value);
+}
+
 }
 }