public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position
@ 2014-12-09 14:06 kariya_mitsuru at hotmail dot com
2014-12-10 13:36 ` [Bug libstdc++/64239] " redi at gcc dot gnu.org
` (10 more replies)
0 siblings, 11 replies; 12+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2014-12-09 14:06 UTC (permalink / raw)
To: gcc-bugs
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'
==================================================================
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
@ 2014-12-10 13:36 ` redi at gcc dot gnu.org
2014-12-10 13:39 ` redi at gcc dot gnu.org
` (9 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-12-10 13:36 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Last reconfirmed| |2014-12-10
CC| |timshen at gcc dot gnu.org
Ever confirmed|0 |1
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
The problem is that match_results::_M_in_iterator is always false after
copy/moving a match_results object. I don't even understand what that member is
for or what's name means. Tim?
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
2014-12-10 13:36 ` [Bug libstdc++/64239] " redi at gcc dot gnu.org
@ 2014-12-10 13:39 ` redi at gcc dot gnu.org
2014-12-10 16:20 ` kariya_mitsuru at hotmail dot com
` (8 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2014-12-10 13:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
match_results::swap() fails to handle _M_in_iterator as well.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
2014-12-10 13:36 ` [Bug libstdc++/64239] " redi at gcc dot gnu.org
2014-12-10 13:39 ` redi at gcc dot gnu.org
@ 2014-12-10 16:20 ` kariya_mitsuru at hotmail dot com
2014-12-11 6:52 ` timshen at gcc dot gnu.org
` (7 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2014-12-10 16:20 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
--- Comment #3 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
Sorry, I confused the copy ctor with the copy assignment operator.
But it seems that both are same results.
operator= version : http://melpon.org/wandbox/permlink/ZHzYukOyuluuzpwu
I didn't notice, but both the copy ctor and the copy assignment operator of
match_results are also same results as Mr. Wakely pointed out above.
copy ctor version : http://melpon.org/wandbox/permlink/Z4Z0kr5yTcB0iyEk
operator= version : http://melpon.org/wandbox/permlink/tHBSWP3hJpinggzw
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
` (2 preceding siblings ...)
2014-12-10 16:20 ` kariya_mitsuru at hotmail dot com
@ 2014-12-11 6:52 ` timshen at gcc dot gnu.org
2014-12-13 22:19 ` timshen at gcc dot gnu.org
` (6 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: timshen at gcc dot gnu.org @ 2014-12-11 6:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
--- Comment #4 from Tim Shen <timshen at gcc dot gnu.org> ---
Sorry, I was once thinking that we should always use
match_results::prefix().first as the "start position of a match". It's true for
regex_match and regex_search, but not true for regex_iterator. That's why
match_results::_M_begin exists.
_M_in_iterator was just a dumb mistake that I can't even understand now,
probably for my misunderstanding on the "start position of a match". Sorry :(
Also, obviously I forgot to update ctor/assign/swap after adding
match_results::_M_match.
I'm testing the patch that fixes this. Later I'll post it in the mailing list.
It removes _M_in_iterator. To backport it to 4.9 branch, _M_in_iterator needs
to remain.
Thanks for reporting and investigating!
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
` (3 preceding siblings ...)
2014-12-11 6:52 ` timshen at gcc dot gnu.org
@ 2014-12-13 22:19 ` timshen at gcc dot gnu.org
2014-12-13 23:11 ` timshen at gcc dot gnu.org
` (5 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: timshen at gcc dot gnu.org @ 2014-12-13 22:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
--- Comment #5 from Tim Shen <timshen at gcc dot gnu.org> ---
Author: timshen
Date: Sat Dec 13 22:19:18 2014
New Revision: 218710
URL: https://gcc.gnu.org/viewcvs?rev=218710&root=gcc&view=rev
Log:
PR libstdc++/64239
* include/bits/regex.h (match_results<>::match_results,
match_results<>::operator=, match_results<>::position,
match_results<>::swap): Remove match_results::_M_in_iterator.
Fix ctor/assign/swap.
* include/bits/regex.tcc: (__regex_algo_impl<>,
regex_iterator<>::operator++): Set match_results::_M_begin as
"start position".
* testsuite/28_regex/iterators/regex_iterator/char/
string_position_01.cc: Test cases.
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/bits/regex.h
trunk/libstdc++-v3/include/bits/regex.tcc
trunk/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
` (4 preceding siblings ...)
2014-12-13 22:19 ` timshen at gcc dot gnu.org
@ 2014-12-13 23:11 ` timshen at gcc dot gnu.org
2015-01-07 3:16 ` kariya_mitsuru at hotmail dot com
` (4 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: timshen at gcc dot gnu.org @ 2014-12-13 23:11 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
--- Comment #6 from Tim Shen <timshen at gcc dot gnu.org> ---
Author: timshen
Date: Sat Dec 13 23:10:39 2014
New Revision: 218711
URL: https://gcc.gnu.org/viewcvs?rev=218711&root=gcc&view=rev
Log:
PR libstdc++/64239
* include/bits/regex.h (match_results<>::match_results,
match_results<>::operator=, match_results<>::position,
match_results<>::swap): Fix ctor/assign/swap.
* include/bits/regex.tcc: (__regex_algo_impl<>,
regex_iterator<>::operator++): Set match_results::_M_begin as
"start position".
* testsuite/28_regex/iterators/regex_iterator/char/
string_position_01.cc: Test cases.
Modified:
branches/gcc-4_9-branch/libstdc++-v3/ChangeLog
branches/gcc-4_9-branch/libstdc++-v3/include/bits/regex.h
branches/gcc-4_9-branch/libstdc++-v3/include/bits/regex.tcc
branches/gcc-4_9-branch/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/string_position_01.cc
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
` (5 preceding siblings ...)
2014-12-13 23:11 ` timshen at gcc dot gnu.org
@ 2015-01-07 3:16 ` kariya_mitsuru at hotmail dot com
2015-01-09 3:59 ` timshen at gcc dot gnu.org
` (3 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2015-01-07 3:16 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
--- Comment #7 from Mitsuru Kariya <kariya_mitsuru at hotmail dot com> ---
When I used the match_results::swap on r218710, I got a compilation error.
========================================== sample code
==========================================
#include <regex>
int main()
{
std::cmatch mm1, mm2;
mm1.swap(mm2);
}
=================================================================================================
========================================== g++ output
===========================================
In file included from /usr/local/gcc-218710/include/c++/5.0.0/regex:59:0,
from swap.cpp:1:
/usr/local/gcc-218710/include/c++/5.0.0/bits/regex.h: In instantiation of 'void
std::match_results< <template-parameter-1-1>, <template-parameter-1-2>
>::swap(std::match_results< <template-parameter-1-1>, <template-parameter-1-2>
>&) [with _Bi_iter = const char*; _Alloc = std::allocator<std::sub_match<const
char*> >]':
swap.cpp:7:15: required from here
/usr/local/gcc-218710/include/c++/5.0.0/bits/regex.h:1864:6: error: no matching
function for call to 'std::match_results<const char*>::swap(const char*&, const
char*&)'
swap(_M_begin, __that._M_begin);
^
/usr/local/gcc-218710/include/c++/5.0.0/bits/regex.h:1861:7: note: candidate:
void std::match_results< <template-parameter-1-1>, <template-parameter-1-2>
>::swap(std::match_results< <template-parameter-1-1>, <template-parameter-1-2>
>&) [with _Bi_iter = const char*; _Alloc = std::allocator<std::sub_match<const
char*> >]
swap(match_results& __that)
^
/usr/local/gcc-218710/include/c++/5.0.0/bits/regex.h:1861:7: note: candidate
expects 1 argument, 2 provided
=================================================================================================
============================================ g++ -v
=============================================
Using built-in specs.
COLLECT_GCC=/usr/local/gcc-218710/bin/g++
COLLECT_LTO_WRAPPER=/usr/local/gcc-218710/libexec/gcc/x86_64-unknown-linux-gnu/5.0.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc.218710/configure --prefix=/usr/local/gcc-218710
--enable-checking=yes --disable-nls --enable-languages=c,c++,lto
Thread model: posix
gcc version 5.0.0 20141213 (experimental) (GCC)
=================================================================================================
Note that the sample code above was compiled successfully on r218555.
I think that the match_results::swap needs "use std::swap;" for swapping
_M_begin.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
` (6 preceding siblings ...)
2015-01-07 3:16 ` kariya_mitsuru at hotmail dot com
@ 2015-01-09 3:59 ` timshen at gcc dot gnu.org
2015-01-09 5:52 ` timshen at gcc dot gnu.org
` (2 subsequent siblings)
10 siblings, 0 replies; 12+ messages in thread
From: timshen at gcc dot gnu.org @ 2015-01-09 3:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
--- Comment #8 from Tim Shen <timshen at gcc dot gnu.org> ---
Author: timshen
Date: Fri Jan 9 03:58:59 2015
New Revision: 219373
URL: https://gcc.gnu.org/viewcvs?rev=219373&root=gcc&view=rev
Log:
PR libstdc++/64239
* include/bits/regex.h (match_results<>::swap): Use std::swap
instead of swap.
* include/bits/regex_compiler.tcc (_Compiler<>::_M_quantifier):
Likewise.
* testsuite/28_regex/match_results/swap.cc: New testcase.
Added:
trunk/libstdc++-v3/testsuite/28_regex/match_results/swap.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/bits/regex.h
trunk/libstdc++-v3/include/bits/regex_compiler.tcc
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
` (7 preceding siblings ...)
2015-01-09 3:59 ` timshen at gcc dot gnu.org
@ 2015-01-09 5:52 ` timshen at gcc dot gnu.org
2015-03-09 6:45 ` timshen at gcc dot gnu.org
2023-07-20 11:42 ` redi at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: timshen at gcc dot gnu.org @ 2015-01-09 5:52 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
--- Comment #9 from Tim Shen <timshen at gcc dot gnu.org> ---
Author: timshen
Date: Fri Jan 9 05:52:18 2015
New Revision: 219374
URL: https://gcc.gnu.org/viewcvs?rev=219374&root=gcc&view=rev
Log:
PR libstdc++/64239
Backported form mainline
2015-01-09 Tim Shen <timshen@google.com>
* include/bits/regex.h (match_results<>::swap): Use std::swap
instead of swap.
* include/bits/regex_compiler.tcc (_Compiler<>::_M_quantifier):
Likewise.
* testsuite/28_regex/match_results/swap.cc: New testcase.
Added:
branches/gcc-4_9-branch/libstdc++-v3/testsuite/28_regex/match_results/swap.cc
Modified:
branches/gcc-4_9-branch/libstdc++-v3/ChangeLog
branches/gcc-4_9-branch/libstdc++-v3/include/bits/regex.h
branches/gcc-4_9-branch/libstdc++-v3/include/bits/regex_compiler.tcc
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
` (8 preceding siblings ...)
2015-01-09 5:52 ` timshen at gcc dot gnu.org
@ 2015-03-09 6:45 ` timshen at gcc dot gnu.org
2023-07-20 11:42 ` redi at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: timshen at gcc dot gnu.org @ 2015-03-09 6:45 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
Tim Shen <timshen at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution|--- |FIXED
--- Comment #10 from Tim Shen <timshen at gcc dot gnu.org> ---
Resolved.
^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug libstdc++/64239] regex_iterator::operator= should copy match_results::position
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
` (9 preceding siblings ...)
2015-03-09 6:45 ` timshen at gcc dot gnu.org
@ 2023-07-20 11:42 ` redi at gcc dot gnu.org
10 siblings, 0 replies; 12+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-20 11:42 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64239
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.9.3
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2023-07-20 11:42 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-09 14:06 [Bug libstdc++/64239] New: regex_iterator::operator= should copy match_results::position kariya_mitsuru at hotmail dot com
2014-12-10 13:36 ` [Bug libstdc++/64239] " redi at gcc dot gnu.org
2014-12-10 13:39 ` redi at gcc dot gnu.org
2014-12-10 16:20 ` kariya_mitsuru at hotmail dot com
2014-12-11 6:52 ` timshen at gcc dot gnu.org
2014-12-13 22:19 ` timshen at gcc dot gnu.org
2014-12-13 23:11 ` timshen at gcc dot gnu.org
2015-01-07 3:16 ` kariya_mitsuru at hotmail dot com
2015-01-09 3:59 ` timshen at gcc dot gnu.org
2015-01-09 5:52 ` timshen at gcc dot gnu.org
2015-03-09 6:45 ` timshen at gcc dot gnu.org
2023-07-20 11:42 ` redi at gcc dot gnu.org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).