From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29101 invoked by alias); 1 Dec 2014 17:35:30 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 29067 invoked by uid 48); 1 Dec 2014 17:35:22 -0000 From: "kariya_mitsuru at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/64140] New: match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match Date: Mon, 01 Dec 2014 17:35:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Version: 5.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kariya_mitsuru at hotmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-12/txt/msg00119.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140 Bug ID: 64140 Summary: match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ Assignee: unassigned at gcc dot gnu.org Reporter: kariya_mitsuru at hotmail dot com Created attachment 34156 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34156&action=edit g++ -v Please see the following sample. ========================================== sample code ========================================== #include #include #include 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), '' ==================================================================