[Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position

kariya_mitsuru at hotmail dot com gcc-bugzilla@gcc.gnu.org
Tue Dec 9 14:06:00 GMT 2014


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

            Bug ID: 64239
           Summary: regex_iterator::operator= should copy
                    match_results::position
           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 34231
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34231&action=edit
g++ -v

Please see the following sample.

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

int main()
{
    std::regex re("\\w+");
    std::string s("-a-b-c-");

    for (auto it1 = std::sregex_iterator(s.begin(), s.end(), re), end =
std::sregex_iterator(); it1 != end; ++it1) {
        auto it2 = it1;
        std::cout << "position() = " << it1->position() << ", length() = " <<
it1->length() << ", str() = '" << it1->str() << "'\n"
                     "position() = " << it2->position() << ", length() = " <<
it2->length() << ", str() = '" << it2->str() << "'\n\n";
    }
}
=================================================================================================

============================= output =============================
position() = 1, length() = 1, str() = 'a'
position() = 1, length() = 1, str() = 'a'

position() = 3, length() = 1, str() = 'b'
position() = 1, length() = 1, str() = 'b'

position() = 5, length() = 1, str() = 'c'
position() = 1, length() = 1, str() = 'c'

==================================================================

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

Though the C++11 standard says nothing about regex_iterator::operator=, I think
that it2->position() should be equal to it1->position().

So, the output should be 

============================= output =============================
position() = 1, length() = 1, str() = 'a'
position() = 1, length() = 1, str() = 'a'

position() = 3, length() = 1, str() = 'b'
position() = 3, length() = 1, str() = 'b'

position() = 5, length() = 1, str() = 'c'
position() = 5, length() = 1, str() = 'c'

==================================================================



More information about the Gcc-bugs mailing list