From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17816 invoked by alias); 31 Dec 2014 14:21:06 -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 17795 invoked by uid 48); 31 Dec 2014 14:21:00 -0000 From: "kariya_mitsuru at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/64441] A match_results returns an incorrect sub_match if the sub_match::matched is false Date: Wed, 31 Dec 2014 14:21:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed 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: Message-ID: In-Reply-To: References: 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/msg02999.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64441 --- Comment #2 from Mitsuru Kariya --- The rev.219121 seems to satisfy the sample code above, but does not satisfy another sample code like below. ====================================== sample code ====================================== #include #include int main() { const char s[] = "abc"; const std::regex re("(\\d+)|(\\w+)"); std::cmatch m; std::regex_search(s, m, re); std::cout << std::boolalpha; for (size_t i = 0, n = m.size(); i <= n; ++i) { auto&& sub = m[i]; std::cout << i << ":" << sub.matched << ", str = '" << sub.str() << "', " "range = [" << sub.first - s << ", " << sub.second - s << ")" << std::endl; } } ========================================================================================= ============================= output ============================= 0:true, str = 'abc', range = [0, 3) 1:false, str = '', range = [3, 3) 2:true, str = 'abc', range = [0, 3) 3:false, str = '', range = [-140735878146800, -140735878146800) ================================================================== According to the C++11 standard 28.10.4[re.results.acc]/p.8, If n >= size() then returns a sub_match object representing an unmatched sub-expression. So, I think that n = 1 and n = 3 should be an identical result, and the output should be ============================= output ============================= 0:true, str = 'abc', range = [0, 3) 1:false, str = '', range = [3, 3) 2:true, str = 'abc', range = [0, 3) 3:false, str = '', range = [3, 3) ==================================================================