aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Shen <timshen@google.com>2014-12-04 04:25:12 +0000
committerTim Shen <timshen@gcc.gnu.org>2014-12-04 04:25:12 +0000
commit9b9c2a974a93393b3993bb84d244844e8a527da9 (patch)
treeea70d254be8eb35eb50f02db8797b7f6e9b63f1e
parentddff61d69b48b6962dc925d5835f86aef34da136 (diff)
downloadgcc-9b9c2a974a93393b3993bb84d244844e8a527da9.zip
gcc-9b9c2a974a93393b3993bb84d244844e8a527da9.tar.gz
gcc-9b9c2a974a93393b3993bb84d244844e8a527da9.tar.bz2
re PR libstdc++/64140 (match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match)
PR libstdc++/64140 * include/bits/regex.tcc (regex_iterator<>::operator++): Update prefix.matched after modifying prefix.first. * testsuite/28_regex/iterators/regex_iterator/char/64140.cc: New testcase. From-SVN: r218340
-rw-r--r--libstdc++-v3/ChangeLog8
-rw-r--r--libstdc++-v3/include/bits/regex.tcc8
-rw-r--r--libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/64140.cc53
3 files changed, 67 insertions, 2 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 3d09b03..e03879f 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,3 +1,11 @@
+2014-12-04 Tim Shen <timshen@google.com>
+
+ PR libstdc++/64140
+ * include/bits/regex.tcc (regex_iterator<>::operator++): Update
+ prefix.matched after modifying prefix.first.
+ * testsuite/28_regex/iterators/regex_iterator/char/64140.cc: New
+ testcase.
+
2014-12-03 François Dumont <fdumont@gcc.gnu.org>
PR libstdc++/13631
diff --git a/libstdc++-v3/include/bits/regex.tcc b/libstdc++-v3/include/bits/regex.tcc
index 94cbbfa..9692402 100644
--- a/libstdc++-v3/include/bits/regex.tcc
+++ b/libstdc++-v3/include/bits/regex.tcc
@@ -569,7 +569,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
| regex_constants::match_continuous))
{
_GLIBCXX_DEBUG_ASSERT(_M_match[0].matched);
- _M_match.at(_M_match.size()).first = __prefix_first;
+ auto& __prefix = _M_match.at(_M_match.size());
+ __prefix.first = __prefix_first;
+ __prefix.matched = __prefix.first != __prefix.second;
_M_match._M_in_iterator = true;
_M_match._M_begin = _M_begin;
return *this;
@@ -582,7 +584,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
if (regex_search(__start, _M_end, _M_match, *_M_pregex, _M_flags))
{
_GLIBCXX_DEBUG_ASSERT(_M_match[0].matched);
- _M_match.at(_M_match.size()).first = __prefix_first;
+ auto& __prefix = _M_match.at(_M_match.size());
+ __prefix.first = __prefix_first;
+ __prefix.matched = __prefix.first != __prefix.second;
_M_match._M_in_iterator = true;
_M_match._M_begin = _M_begin;
}
diff --git a/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/64140.cc b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/64140.cc
new file mode 100644
index 0000000..32b7e24
--- /dev/null
+++ b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/64140.cc
@@ -0,0 +1,53 @@
+// { dg-options "-std=gnu++11" }
+
+//
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// libstdc++/64140
+
+#include <regex>
+#include <testsuite_hooks.h>
+
+void
+test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ const std::regex e("z*");
+ const std::string s("ab");
+
+ auto it = std::sregex_iterator(s.begin(), s.end(), e);
+ auto end = std::sregex_iterator();
+ VERIFY(it != end);
+ VERIFY(!it->prefix().matched);
+ ++it;
+ VERIFY(it != end);
+ VERIFY(it->prefix().matched);
+ ++it;
+ VERIFY(it != end);
+ VERIFY(it->prefix().matched);
+ ++it;
+ VERIFY(it == end);
+}
+
+int
+main()
+{
+ test01();
+ return 0;
+}