[libcxx] Update optional star operator to be noexcept.
authorzoecarver <z.zoelec2@gmail.com>
Thu, 1 Jul 2021 17:18:27 +0000 (10:18 -0700)
committerzoecarver <z.zoelec2@gmail.com>
Thu, 1 Jul 2021 17:42:46 +0000 (10:42 -0700)
Differential Revision: https://reviews.llvm.org/D105296

libcxx/include/optional
libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference.pass.cpp
libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference_const.pass.cpp
libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference_const_rvalue.pass.cpp
libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference_rvalue.pass.cpp

index 0e6c1b8..118db66 100644 (file)
@@ -906,7 +906,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     constexpr
     const value_type&
-    operator*() const&
+    operator*() const& noexcept
     {
         _LIBCPP_ASSERT(this->has_value(), "optional operator* called on a disengaged value");
         return this->__get();
@@ -915,7 +915,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     constexpr
     value_type&
-    operator*() &
+    operator*() & noexcept
     {
         _LIBCPP_ASSERT(this->has_value(), "optional operator* called on a disengaged value");
         return this->__get();
@@ -924,7 +924,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     constexpr
     value_type&&
-    operator*() &&
+    operator*() && noexcept
     {
         _LIBCPP_ASSERT(this->has_value(), "optional operator* called on a disengaged value");
         return _VSTD::move(this->__get());
@@ -933,7 +933,7 @@ public:
     _LIBCPP_INLINE_VISIBILITY
     constexpr
     const value_type&&
-    operator*() const&&
+    operator*() const&& noexcept
     {
         _LIBCPP_ASSERT(this->has_value(), "optional operator* called on a disengaged value");
         return _VSTD::move(this->__get());
index 98216df..5b04e5a 100644 (file)
@@ -44,6 +44,7 @@ int main(int, char**)
     {
         optional<X> opt; ((void)opt);
         ASSERT_SAME_TYPE(decltype(*opt), X&);
+        LIBCPP_STATIC_ASSERT(noexcept(*opt));
         // ASSERT_NOT_NOEXCEPT(*opt);
         // FIXME: This assertion fails with GCC because it can see that
         // (A) operator*() is constexpr, and
index f61cfce..f323cd1 100644 (file)
@@ -37,6 +37,7 @@ int main(int, char**)
     {
         const optional<X> opt; ((void)opt);
         ASSERT_SAME_TYPE(decltype(*opt), X const&);
+        LIBCPP_STATIC_ASSERT(noexcept(*opt));
         // ASSERT_NOT_NOEXCEPT(*opt);
         // FIXME: This assertion fails with GCC because it can see that
         // (A) operator*() is constexpr, and
index bc6745d..68591c5 100644 (file)
@@ -37,6 +37,7 @@ int main(int, char**)
     {
         const optional<X> opt; ((void)opt);
         ASSERT_SAME_TYPE(decltype(*std::move(opt)), X const &&);
+        LIBCPP_STATIC_ASSERT(noexcept(*opt));
         // ASSERT_NOT_NOEXCEPT(*std::move(opt));
         // FIXME: This assertion fails with GCC because it can see that
         // (A) operator*() is constexpr, and
index c8ee573..67edbb9 100644 (file)
@@ -44,6 +44,7 @@ int main(int, char**)
     {
         optional<X> opt; ((void)opt);
         ASSERT_SAME_TYPE(decltype(*std::move(opt)), X&&);
+        LIBCPP_STATIC_ASSERT(noexcept(*opt));
         // ASSERT_NOT_NOEXCEPT(*std::move(opt));
         // FIXME: This assertion fails with GCC because it can see that
         // (A) operator*() is constexpr, and