aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3/testsuite/28_regex
diff options
context:
space:
mode:
authorTim Shen <timshen@google.com>2014-12-13 22:19:18 +0000
committerTim Shen <timshen@gcc.gnu.org>2014-12-13 22:19:18 +0000
commitbc2738455bf4e405cf0ad3d61482b49cd4382113 (patch)
tree8fbd14b1bfca1e100c674f1a08fca314b98923e6 /libstdc++-v3/testsuite/28_regex
parent6554581713da6cc9bb96cf86cf7a0cece80a448e (diff)
downloadgcc-bc2738455bf4e405cf0ad3d61482b49cd4382113.zip
gcc-bc2738455bf4e405cf0ad3d61482b49cd4382113.tar.gz
gcc-bc2738455bf4e405cf0ad3d61482b49cd4382113.tar.bz2
re PR libstdc++/64239 (regex_iterator::operator= should copy match_results::position)
PR libstdc++/64239 * include/bits/regex.h (match_results<>::match_results, match_results<>::operator=, match_results<>::position, match_results<>::swap): Remove match_results::_M_in_iterator. Fix ctor/assign/swap. * include/bits/regex.tcc: (__regex_algo_impl<>, regex_iterator<>::operator++): Set match_results::_M_begin as "start position". * testsuite/28_regex/iterators/regex_iterator/char/ string_position_01.cc: Test cases. From-SVN: r218710
Diffstat (limited to 'libstdc++-v3/testsuite/28_regex')
-rw-r--r--libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc45
1 files changed, 45 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc
index 5fa4ea7..91aa061 100644
--- a/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc
+++ b/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc
@@ -24,6 +24,7 @@
// Tests iter->position() behavior
#include <regex>
+#include <tuple>
#include <testsuite_hooks.h>
void
@@ -41,9 +42,53 @@ test01()
}
}
+// PR libstdc++/64239
+void
+test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::regex re("\\w+");
+ std::string s("-a-b-c-");
+
+ std::tuple<int, int, const char*> expected[] =
+ {
+ std::make_tuple(1, 1, "a"),
+ std::make_tuple(3, 1, "b"),
+ std::make_tuple(5, 1, "c"),
+ };
+
+ int i = 0;
+ for (auto it1 = std::sregex_iterator(s.begin(), s.end(), re),
+ end = std::sregex_iterator(); it1 != end; ++it1, i++)
+ {
+ auto it2 = it1;
+ VERIFY(it1->position() == std::get<0>(expected[i]));
+ VERIFY(it1->length() == std::get<1>(expected[i]));
+ VERIFY(it1->str() == std::get<2>(expected[i]));
+ VERIFY(it2->position() == std::get<0>(expected[i]));
+ VERIFY(it2->length() == std::get<1>(expected[i]));
+ VERIFY(it2->str() == std::get<2>(expected[i]));
+ }
+}
+
+void
+test03()
+{
+ bool test __attribute__((unused)) = true;
+
+ std::smatch m;
+ std::string s = "abcde";
+ std::regex_search(s, m, std::regex("bcd"));
+ VERIFY(m.position() == 1);
+ VERIFY(m.position() == m.prefix().length());
+}
+
int
main()
{
test01();
+ test02();
+ test03();
return 0;
}