Created attachment 34156 [details] g++ -v Please see the following sample. ========================================== sample code ========================================== #include <iostream> #include <regex> #include <string> void print(const char* t, const std::string& s, const std::ssub_match& sub) { std::cout << " " << t << ": " << (sub.matched ? "matched " : "unmatched") << ", " "length() = " << sub.length() << ", str() = '" << sub.str() << "\', " "pair = (" << sub.first - s.begin() << ", " << sub.second - s.begin() << "), " "'" << std::string(sub.first, sub.second) << '\'' << std::endl; } int main() { const std::regex e("z*"); const std::string s("ab"); int i = 0; for (auto&& it = std::sregex_iterator(s.begin(), s.end(), e), end = std::sregex_iterator(); it != end; ++it) { std::cout << i++ << ':' << std::endl; print("prefix", s, it->prefix()); print("match ", s, (*it)[0]); std::cout << std::endl; } } ================================================================================================= ============================= output ============================= 0: prefix: unmatched, length() = 0, str() = '', pair = (0, 0), '' match : matched , length() = 0, str() = '', pair = (0, 0), '' 1: prefix: unmatched, length() = 0, str() = '', pair = (0, 1), 'a' match : matched , length() = 0, str() = '', pair = (1, 1), '' 2: prefix: unmatched, length() = 0, str() = '', pair = (1, 2), 'b' match : matched , length() = 0, str() = '', pair = (2, 2), '' ================================================================== cf. http://melpon.org/wandbox/permlink/JSkP6tl2QWFxmOEv According to C++11 standard 28.11.3[re.alg.search]/p.3 Table 143, prefix().matched should be true if prefix().first != prefix().second. (prefix().first is correct, because 28.12.1.4[re.regiter.incr]/p.5 says "match.prefix().first shall be equal to the previous value of match[0].second".) So, I think that the output should be ============================= output ============================= 0: prefix: unmatched, length() = 0, str() = '', pair = (0, 0), '' match : matched , length() = 0, str() = '', pair = (0, 0), '' 1: prefix: matched , length() = 1, str() = 'a', pair = (0, 1), 'a' match : matched , length() = 0, str() = '', pair = (1, 1), '' 2: prefix: matched , length() = 1, str() = 'b', pair = (1, 2), 'b' match : matched , length() = 0, str() = '', pair = (2, 2), '' ==================================================================
Author: timshen Date: Thu Dec 4 04:25:12 2014 New Revision: 218340 URL: https://gcc.gnu.org/viewcvs?rev=218340&root=gcc&view=rev Log: 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. Added: trunk/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/64140.cc Modified: trunk/libstdc++-v3/ChangeLog trunk/libstdc++-v3/include/bits/regex.tcc
Author: timshen Date: Sat Dec 6 11:32:21 2014 New Revision: 218445 URL: https://gcc.gnu.org/viewcvs?rev=218445&root=gcc&view=rev Log: PR libstdc++/64140 Backport form mainline 2014-12-04 Tim Shen <timshen@google.com> * 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. Added: branches/gcc-4_9-branch/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/64140.cc Modified: branches/gcc-4_9-branch/libstdc++-v3/ChangeLog branches/gcc-4_9-branch/libstdc++-v3/include/bits/regex.tcc
Resolved.