From e00d350bbdf86bbcd3ed84aebd7c007b12ebd5a1 Mon Sep 17 00:00:00 2001 From: Marshall Clow Date: Wed, 5 Jul 2017 16:37:19 +0000 Subject: [PATCH] Fix a bug in regex_Iterator where it would report zero-length matches forever. Reported as http://llvm.org/PR33681. Thanks to Karen Arutyunov for the report. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@307171 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/regex | 2 +- .../re.regiter/re.regiter.incr/post.pass.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/include/regex b/include/regex index 443c2e303..77ca64810 100644 --- a/include/regex +++ b/include/regex @@ -6142,7 +6142,7 @@ regex_iterator<_BidirectionalIterator, _CharT, _Traits>::operator++() { __flags_ |= regex_constants::__no_update_pos; _BidirectionalIterator __start = __match_[0].second; - if (__match_.empty()) + if (__match_[0].first == __match_[0].second) { if (__start == __end_) { diff --git a/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp b/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp index f3b57f6bc..5e3ad4d91 100644 --- a/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp +++ b/test/std/re/re.iter/re.regiter/re.regiter.incr/post.pass.cpp @@ -95,4 +95,22 @@ int main() assert((*i2).position() == 0); assert((*i2).str() == "555-1234"); } + { // http://llvm.org/PR33681 + std::regex rex(".*"); + const char foo[] = "foo"; + // The -1 is because we don't want the implicit null from the array. + std::cregex_iterator i(std::begin(foo), std::end(foo) - 1, rex); + std::cregex_iterator e; + assert(i != e); + assert((*i).size() == 1); + assert((*i).str() == "foo"); + + ++i; + assert(i != e); + assert((*i).size() == 1); + assert((*i).str() == ""); + + ++i; + assert(i == e); + } }