@@ -4587,28 +4587,36 @@ public:
4587
4587
4588
4588
// element access:
4589
4589
_LIBCPP_HIDE_FROM_ABI difference_type length (size_type __sub = 0 ) const {
4590
- _LIBCPP_ASSERT_UNCATEGORIZED (ready (), " match_results::length() called when not ready" );
4590
+ // If the match results are not ready, this will return `0`.
4591
+ _LIBCPP_ASSERT_PEDANTIC (ready (), " match_results::length() called when not ready" );
4591
4592
return (*this )[__sub].length ();
4592
4593
}
4593
4594
_LIBCPP_HIDE_FROM_ABI difference_type position (size_type __sub = 0 ) const {
4594
- _LIBCPP_ASSERT_UNCATEGORIZED (ready (), " match_results::position() called when not ready" );
4595
+ // If the match results are not ready, this will return the result of subtracting two default-constructed iterators
4596
+ // (which is typically a well-defined operation).
4597
+ _LIBCPP_ASSERT_PEDANTIC (ready (), " match_results::position() called when not ready" );
4595
4598
return std::distance (__position_start_, (*this )[__sub].first );
4596
4599
}
4597
4600
_LIBCPP_HIDE_FROM_ABI string_type str (size_type __sub = 0 ) const {
4598
- _LIBCPP_ASSERT_UNCATEGORIZED (ready (), " match_results::str() called when not ready" );
4601
+ // If the match results are not ready, this will return an empty string.
4602
+ _LIBCPP_ASSERT_PEDANTIC (ready (), " match_results::str() called when not ready" );
4599
4603
return (*this )[__sub].str ();
4600
4604
}
4601
4605
_LIBCPP_HIDE_FROM_ABI const_reference operator [](size_type __n) const {
4602
- _LIBCPP_ASSERT_UNCATEGORIZED (ready (), " match_results::operator[]() called when not ready" );
4606
+ // If the match results are not ready, this call will be equivalent to calling this function with `__n >= size()`,
4607
+ // returning an empty subrange.
4608
+ _LIBCPP_ASSERT_PEDANTIC (ready (), " match_results::operator[]() called when not ready" );
4603
4609
return __n < __matches_.size () ? __matches_[__n] : __unmatched_;
4604
4610
}
4605
4611
4606
4612
_LIBCPP_HIDE_FROM_ABI const_reference prefix () const {
4607
- _LIBCPP_ASSERT_UNCATEGORIZED (ready (), " match_results::prefix() called when not ready" );
4613
+ // If the match results are not ready, this will return a default-constructed empty `__suffix_`.
4614
+ _LIBCPP_ASSERT_PEDANTIC (ready (), " match_results::prefix() called when not ready" );
4608
4615
return __prefix_;
4609
4616
}
4610
4617
_LIBCPP_HIDE_FROM_ABI const_reference suffix () const {
4611
- _LIBCPP_ASSERT_UNCATEGORIZED (ready (), " match_results::suffix() called when not ready" );
4618
+ // If the match results are not ready, this will return a default-constructed empty `__suffix_`.
4619
+ _LIBCPP_ASSERT_PEDANTIC (ready (), " match_results::suffix() called when not ready" );
4612
4620
return __suffix_;
4613
4621
}
4614
4622
@@ -4722,7 +4730,8 @@ _OutputIter match_results<_BidirectionalIterator, _Allocator>::format(
4722
4730
const char_type* __fmt_first,
4723
4731
const char_type* __fmt_last,
4724
4732
regex_constants::match_flag_type __flags) const {
4725
- _LIBCPP_ASSERT_UNCATEGORIZED (ready (), " match_results::format() called when not ready" );
4733
+ // Note: this duplicates a check in `vector::operator[]` but provides a better error message.
4734
+ _LIBCPP_ASSERT_VALID_ELEMENT_ACCESS (ready (), " match_results::format() called when not ready" );
4726
4735
if (__flags & regex_constants::format_sed) {
4727
4736
for (; __fmt_first != __fmt_last; ++__fmt_first) {
4728
4737
if (*__fmt_first == ' &' )
0 commit comments