[libcxx-commits] [PATCH] D105296: [libcxx] Update optional star operator to be noexcept.

Zoe Carver via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu Jul 1 10:18:59 PDT 2021


zoecarver created this revision.
zoecarver requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D105296

Files:
  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: libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference_rvalue.pass.cpp
===================================================================
--- libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference_rvalue.pass.cpp
+++ libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference_rvalue.pass.cpp
@@ -44,6 +44,7 @@
     {
         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
Index: 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_const_rvalue.pass.cpp
+++ libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference_const_rvalue.pass.cpp
@@ -37,6 +37,7 @@
     {
         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: 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.pass.cpp
+++ libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference_const.pass.cpp
@@ -37,6 +37,7 @@
     {
         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: libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference.pass.cpp
===================================================================
--- libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference.pass.cpp
+++ libcxx/test/std/utilities/optional/optional.object/optional.object.observe/dereference.pass.cpp
@@ -44,6 +44,7 @@
     {
         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: libcxx/include/optional
===================================================================
--- libcxx/include/optional
+++ libcxx/include/optional
@@ -906,7 +906,7 @@
     _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 @@
     _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 @@
     _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 @@
     _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());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105296.355930.patch
Type: text/x-patch
Size: 4168 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210701/1603c863/attachment-0001.bin>


More information about the libcxx-commits mailing list