[Bug libstdc++/64302] New: The match_results::cbegin()/cend() return incorrect results

kariya_mitsuru at hotmail dot com gcc-bugzilla@gcc.gnu.org
Sun Dec 14 09:51:00 GMT 2014


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64302

            Bug ID: 64302
           Summary: The match_results::cbegin()/cend() return incorrect
                    results
           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 34277
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34277&action=edit
g++ -v

The match_results::cbegin()/cend() should return identical results as the
match_results::begin()/end() but the match_results::cbegin()/cend() return
incorrect results by libstdc++.

============================== sample code ==============================
#include <iostream>
#include <regex>
#include <string>

int main()
{
    std::string s("  111  222  ");
    std::regex re("(\\d+)\\s+(\\d+)");
    std::smatch m;
    if (std::regex_search(s, m, re)) {
        std::cout << "begin - end" << std::endl;
        for (auto&& it = m.begin(), end = m.end(); it != end; ++it) {
            std::cout << '\'' << *it << '\'' << std::endl;
        }
        std::cout << "cbegin - cend" << std::endl;
        for (auto&& it = m.cbegin(), end = m.cend(); it != end; ++it) {
            std::cout << '\'' << *it << '\'' << std::endl;
        }
    } else {
        std::cout << "unmatch!" << std::endl;
    }
}
=========================================================================

============================= output =============================
begin - end
'111  222'
'111'
'222'
cbegin - cend
'222'
'  '
'  '
==================================================================

cf. http://melpon.org/wandbox/permlink/Xhkav0mRRdT5wRXw


According to the C++11 standard 28.10.4[re.results.acc]/p.13 & p.14, the
match_results::cbegin()/cend() has same difinitions as the
match_results::begin()/end().



More information about the Gcc-bugs mailing list