optional (_Optional_base::_M_get): Check precondition.
authorMarc Glisse <marc.glisse@inria.fr>
Tue, 16 May 2017 12:54:16 +0000 (14:54 +0200)
committerMarc Glisse <glisse@gcc.gnu.org>
Tue, 16 May 2017 12:54:16 +0000 (12:54 +0000)
2017-05-16  Marc Glisse  <marc.glisse@inria.fr>

* include/std/optional (_Optional_base::_M_get): Check precondition.
* testsuite/20_util/optional/cons/value_neg.cc: Update line numbers.

From-SVN: r248099

libstdc++-v3/ChangeLog
libstdc++-v3/include/std/optional
libstdc++-v3/testsuite/20_util/optional/cons/value_neg.cc

index f228a394b60b1973e10c51ef8629c9c0a72e3113..0fea52b7f40bd2333b571f3af0654e2b56731201 100644 (file)
@@ -1,3 +1,8 @@
+2017-05-16  Marc Glisse  <marc.glisse@inria.fr>
+
+       * include/std/optional (_Optional_base::_M_get): Check precondition.
+       * testsuite/20_util/optional/cons/value_neg.cc: Update line numbers.
+
 2017-05-16  Jonathan Wakely  <jwakely@redhat.com>
 
        * doc/xml/manual/appendix_contributing.xml: Link to test docs and
index 5aa926f0cfd84727c59e08d6dcf36f232f05911b..c697c1682a60f7539010a1a3321803ad3b21c8cf 100644 (file)
@@ -386,11 +386,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       // The _M_get operations have _M_engaged as a precondition.
       constexpr _Tp&
       _M_get() noexcept
-      { return this->_M_payload._M_payload; }
+      {
+       __glibcxx_assert(_M_is_engaged());
+       return this->_M_payload._M_payload;
+      }
 
       constexpr const _Tp&
       _M_get() const noexcept
-      { return this->_M_payload._M_payload; }
+      {
+       __glibcxx_assert(_M_is_engaged());
+       return this->_M_payload._M_payload;
+      }
 
       // The _M_construct operation has !_M_engaged as a precondition
       // while _M_destruct has _M_engaged as a precondition.
index 5abe26e433d396f2787264496fe301504a6380c8..524e302fec10b250cd52a47040d405a3c95c6003 100644 (file)
@@ -37,8 +37,8 @@ int main()
     std::optional<std::unique_ptr<int>> oup2 = new int;  // { dg-error "conversion" }
     struct U { explicit U(std::in_place_t); };
     std::optional<U> ou(std::in_place); // { dg-error "no matching" }
-    // { dg-error "no type" "" { target { *-*-* } } 487 }
-    // { dg-error "no type" "" { target { *-*-* } } 497 }
-    // { dg-error "no type" "" { target { *-*-* } } 554 }
+    // { dg-error "no type" "" { target { *-*-* } } 493 }
+    // { dg-error "no type" "" { target { *-*-* } } 503 }
+    // { dg-error "no type" "" { target { *-*-* } } 560 }
   }
 }