Add '_LIBCPP_ASSERT(ready())' to several match_results method that have this precondt...
authorMarshall Clow <mclow.lists@gmail.com>
Fri, 26 Apr 2019 17:10:03 +0000 (17:10 +0000)
committerMarshall Clow <mclow.lists@gmail.com>
Fri, 26 Apr 2019 17:10:03 +0000 (17:10 +0000)
llvm-svn: 359324

libcxx/include/regex
libcxx/test/std/re/re.results/re.results.all/get_allocator.pass.cpp
libcxx/test/std/re/re.results/re.results.const/allocator.pass.cpp
libcxx/test/std/re/re.results/re.results.const/copy.pass.cpp
libcxx/test/std/re/re.results/re.results.const/copy_assign.pass.cpp
libcxx/test/std/re/re.results/re.results.const/default.pass.cpp
libcxx/test/std/re/re.results/re.results.const/move.pass.cpp
libcxx/test/std/re/re.results/re.results.const/move_assign.pass.cpp

index b9aa9d63395a7b496e8aff42053012d55c539f54..1f397cd41f7d3923d445d304c6570817a102936c 100644 (file)
@@ -5296,21 +5296,41 @@ public:
     // element access:
     _LIBCPP_INLINE_VISIBILITY
     difference_type length(size_type __sub = 0) const
-        {return (*this)[__sub].length();}
+        {
+        _LIBCPP_ASSERT(ready(), "match_results::length() called when not ready");
+        return (*this)[__sub].length();
+        }
     _LIBCPP_INLINE_VISIBILITY
     difference_type position(size_type __sub = 0) const
-        {return _VSTD::distance(__position_start_, (*this)[__sub].first);}
+        {
+        _LIBCPP_ASSERT(ready(), "match_results::position() called when not ready");
+        return _VSTD::distance(__position_start_, (*this)[__sub].first);
+        }
     _LIBCPP_INLINE_VISIBILITY
     string_type str(size_type __sub = 0) const
-        {return (*this)[__sub].str();}
+        {
+        _LIBCPP_ASSERT(ready(), "match_results::str() called when not ready");
+        return (*this)[__sub].str();
+        }
     _LIBCPP_INLINE_VISIBILITY
     const_reference operator[](size_type __n) const
-        {return __n < __matches_.size() ? __matches_[__n] : __unmatched_;}
+        {
+        _LIBCPP_ASSERT(ready(), "match_results::operator[]() called when not ready");
+        return __n < __matches_.size() ? __matches_[__n] : __unmatched_;
+        }
 
     _LIBCPP_INLINE_VISIBILITY
-    const_reference prefix() const {return __prefix_;}
+    const_reference prefix() const
+        {
+        _LIBCPP_ASSERT(ready(), "match_results::prefix() called when not ready");
+        return __prefix_;
+        }
     _LIBCPP_INLINE_VISIBILITY
-    const_reference suffix() const {return __suffix_;}
+    const_reference suffix() const
+        {
+        _LIBCPP_ASSERT(ready(), "match_results::suffix() called when not ready");
+        return __suffix_;
+        }
 
     _LIBCPP_INLINE_VISIBILITY
     const_iterator begin() const {return empty() ? __matches_.end() : __matches_.begin();}
@@ -5448,6 +5468,7 @@ match_results<_BidirectionalIterator, _Allocator>::format(_OutputIter __output_i
         const char_type* __fmt_first, const char_type* __fmt_last,
         regex_constants::match_flag_type __flags) const
 {
+    _LIBCPP_ASSERT(ready(), "match_results::format() called when not ready");
     if (__flags & regex_constants::format_sed)
     {
         for (; __fmt_first != __fmt_last; ++__fmt_first)
index f0dcd7b6d42c369b6a995bbbdebeab05cd7a435c..33b5970d88b547e511dec6980b5bd3650de8c60f 100644 (file)
@@ -24,7 +24,7 @@ test(const Allocator& a)
 {
     std::match_results<const CharT*, Allocator> m(a);
     assert(m.size() == 0);
-    assert(m.str() == std::basic_string<CharT>());
+    assert(!m.ready());
     assert(m.get_allocator() == a);
 }
 
index 99ecb667b7528f5f76e8921aa201058fd6f1732f..659954607cae5e8e31bb0bbcd58f06b830024e77 100644 (file)
@@ -24,7 +24,7 @@ test(const Allocator& a)
 {
     std::match_results<const CharT*, Allocator> m(a);
     assert(m.size() == 0);
-    assert(m.str() == std::basic_string<CharT>());
+    assert(!m.ready());
     assert(m.get_allocator() == a);
 }
 
index a1dbea0e84026e0edbaec2d5b258a6fa72d29d99..88b8093449e93c6edc3869f3debce070fef62185 100644 (file)
@@ -26,7 +26,7 @@ test(const Allocator& a)
     SM m1(m0);
 
     assert(m1.size()          == m0.size());
-    assert(m1.str()           == m0.str());
+    assert(m1.ready()         == m0.ready());
     assert(m1.get_allocator() == m0.get_allocator());
 }
 
index 943037e752fdc9a2545b6aa6ac5efca7e4067383..1b220dfb899313f6f1d1aafc43d9963fd6bb5458 100644 (file)
@@ -27,7 +27,7 @@ test(const Allocator& a)
 
     m1 = m0;
     assert(m1.size()          == m0.size());
-    assert(m1.str()           == m0.str());
+    assert(m1.ready()         == m0.ready());
     if (std::allocator_traits<Allocator>::propagate_on_container_copy_assignment::value)
         assert(m1.get_allocator() == m0.get_allocator());
     else
index a70c3441db3f4b73273134533bf26e50f7faea5c..783cd29423d48a09c1e08014ce12f41bb27f5f82 100644 (file)
@@ -22,7 +22,7 @@ test()
 {
     std::match_results<const CharT*> m;
     assert(m.size() == 0);
-    assert(m.str() == std::basic_string<CharT>());
+    assert(!m.ready());
     assert(m.get_allocator() == std::allocator<std::sub_match<const CharT*> >());
 }
 
index 778e31b26f7ee514ee88fba618e611503325f15a..eb292d3a260cddf658337b5de51c3f43181a0d75 100644 (file)
@@ -31,7 +31,7 @@ test(const Allocator& a)
 
     SM m1(std::move(m0));
     assert(m1.size() == 0);
-    assert(m1.str() == std::basic_string<CharT>());
+    assert(!m1.ready());
     assert(m1.get_allocator() == a);
 }
 
index 2a62af8f297784f2bf826ea9878e833a30e3d264..42393f1d2c8e1b565808898ef59001a413ded7a8 100644 (file)
@@ -28,7 +28,7 @@ test(const Allocator& a)
 
     m1 = std::move(m0);
     assert(m1.size()          == 0);
-    assert(m1.str()           == std::basic_string<CharT>());
+    assert(!m1.ready());
     if (std::allocator_traits<Allocator>::propagate_on_container_move_assignment::value)
         assert(m1.get_allocator() == a);
     else