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

            Bug ID: 64303
           Summary: The regex_token_iterator's copy constructor creates an
                    incorrect iterator
           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 34278
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34278&action=edit
g++ -v

Please see the following sample.

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

int main()
{
  const std::string s("  111  222  ");
  const std::regex re("\\w+");

  std::sregex_token_iterator it1(s.begin(), s.end(), re), it2(it1), end;

  for (; it1 != end; ++it1) {
    std::cout << "range = (" << it1->first - s.begin() << ", " << it1->second -
s.begin() << "), "
                 "str = '" << it1->str() << '\'' << std::endl;
  }
  std::cout << std::endl;

  for (; it2 != end; ++it2) {
    std::cout << "range = (" << it2->first - s.begin() << ", " << it2->second -
s.begin() << "), "
                 "str = '" << it2->str() << '\'' << std::endl;
  }
}
=================================================================================================

============================= output =============================
range = (2, 5), str = '111'
range = (7, 10), str = '222'

range = (488, 10), str = ''
range = (7, 10), str = '222'

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

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

Though the C++11 standard says nothing about the regex_token_iterator's copy
constructor, I think that *it2 should be equal to *it1.

So, the output should be

============================= output =============================
range = (2, 5), str = '111'
range = (7, 10), str = '222'

range = (2, 5), str = '111'
range = (7, 10), str = '222'

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

Note that the operator= is a same result.

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

Reply via email to