[libcxx-commits] [libcxx] r359324 - Add '_LIBCPP_ASSERT(ready())' to several match_results method that have this precondtion. Fix several tests which did not honor this precondition. Thanks to Andrey Maksimov for pointing this out.

Marshall Clow via libcxx-commits libcxx-commits at lists.llvm.org
Fri Apr 26 10:10:04 PDT 2019


Author: marshall
Date: Fri Apr 26 10:10:03 2019
New Revision: 359324

URL: http://llvm.org/viewvc/llvm-project?rev=359324&view=rev
Log:
Add '_LIBCPP_ASSERT(ready())' to several match_results method that have this precondtion. Fix several tests which did not honor this precondition. Thanks to Andrey Maksimov for pointing this out.

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

Modified: libcxx/trunk/include/regex
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/regex?rev=359324&r1=359323&r2=359324&view=diff
==============================================================================
--- libcxx/trunk/include/regex (original)
+++ libcxx/trunk/include/regex Fri Apr 26 10:10:03 2019
@@ -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, _A
         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)

Modified: libcxx/trunk/test/std/re/re.results/re.results.all/get_allocator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.all/get_allocator.pass.cpp?rev=359324&r1=359323&r2=359324&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.all/get_allocator.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.results/re.results.all/get_allocator.pass.cpp Fri Apr 26 10:10:03 2019
@@ -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);
 }
 

Modified: libcxx/trunk/test/std/re/re.results/re.results.const/allocator.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.const/allocator.pass.cpp?rev=359324&r1=359323&r2=359324&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.const/allocator.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.results/re.results.const/allocator.pass.cpp Fri Apr 26 10:10:03 2019
@@ -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);
 }
 

Modified: libcxx/trunk/test/std/re/re.results/re.results.const/copy.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.const/copy.pass.cpp?rev=359324&r1=359323&r2=359324&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.const/copy.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.results/re.results.const/copy.pass.cpp Fri Apr 26 10:10:03 2019
@@ -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());
 }
 

Modified: libcxx/trunk/test/std/re/re.results/re.results.const/copy_assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.const/copy_assign.pass.cpp?rev=359324&r1=359323&r2=359324&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.const/copy_assign.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.results/re.results.const/copy_assign.pass.cpp Fri Apr 26 10:10:03 2019
@@ -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

Modified: libcxx/trunk/test/std/re/re.results/re.results.const/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.const/default.pass.cpp?rev=359324&r1=359323&r2=359324&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.const/default.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.results/re.results.const/default.pass.cpp Fri Apr 26 10:10:03 2019
@@ -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*> >());
 }
 

Modified: libcxx/trunk/test/std/re/re.results/re.results.const/move.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.const/move.pass.cpp?rev=359324&r1=359323&r2=359324&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.const/move.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.results/re.results.const/move.pass.cpp Fri Apr 26 10:10:03 2019
@@ -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);
 }
 

Modified: libcxx/trunk/test/std/re/re.results/re.results.const/move_assign.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/re/re.results/re.results.const/move_assign.pass.cpp?rev=359324&r1=359323&r2=359324&view=diff
==============================================================================
--- libcxx/trunk/test/std/re/re.results/re.results.const/move_assign.pass.cpp (original)
+++ libcxx/trunk/test/std/re/re.results/re.results.const/move_assign.pass.cpp Fri Apr 26 10:10:03 2019
@@ -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




More information about the libcxx-commits mailing list