public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/64140] New: match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match
@ 2014-12-01 17:35 kariya_mitsuru at hotmail dot com
2014-12-04 4:25 ` [Bug libstdc++/64140] " timshen at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: kariya_mitsuru at hotmail dot com @ 2014-12-01 17:35 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140
Bug ID: 64140
Summary: match_results.prefix() returns an incorrect result if
regex_iterator holds a zero-length match
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 34156
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34156&action=edit
g++ -v
Please see the following sample.
========================================== sample code
==========================================
#include <iostream>
#include <regex>
#include <string>
void print(const char* t, const std::string& s, const std::ssub_match& sub)
{
std::cout << " " << t << ": " << (sub.matched ? "matched " : "unmatched")
<< ", "
"length() = " << sub.length() << ", str() = '" << sub.str() << "\', "
"pair = (" << sub.first - s.begin() << ", " << sub.second - s.begin()
<< "), "
"'" << std::string(sub.first, sub.second) << '\'' << std::endl;
}
int main()
{
const std::regex e("z*");
const std::string s("ab");
int i = 0;
for (auto&& it = std::sregex_iterator(s.begin(), s.end(), e), end =
std::sregex_iterator();
it != end; ++it) {
std::cout << i++ << ':' << std::endl;
print("prefix", s, it->prefix());
print("match ", s, (*it)[0]);
std::cout << std::endl;
}
}
=================================================================================================
============================= output =============================
0:
prefix: unmatched, length() = 0, str() = '', pair = (0, 0), ''
match : matched , length() = 0, str() = '', pair = (0, 0), ''
1:
prefix: unmatched, length() = 0, str() = '', pair = (0, 1), 'a'
match : matched , length() = 0, str() = '', pair = (1, 1), ''
2:
prefix: unmatched, length() = 0, str() = '', pair = (1, 2), 'b'
match : matched , length() = 0, str() = '', pair = (2, 2), ''
==================================================================
cf. http://melpon.org/wandbox/permlink/JSkP6tl2QWFxmOEv
According to C++11 standard 28.11.3[re.alg.search]/p.3 Table 143,
prefix().matched should be true
if prefix().first != prefix().second.
(prefix().first is correct, because 28.12.1.4[re.regiter.incr]/p.5 says
"match.prefix().first
shall be equal to the previous value of match[0].second".)
So, I think that the output should be
============================= output =============================
0:
prefix: unmatched, length() = 0, str() = '', pair = (0, 0), ''
match : matched , length() = 0, str() = '', pair = (0, 0), ''
1:
prefix: matched , length() = 1, str() = 'a', pair = (0, 1), 'a'
match : matched , length() = 0, str() = '', pair = (1, 1), ''
2:
prefix: matched , length() = 1, str() = 'b', pair = (1, 2), 'b'
match : matched , length() = 0, str() = '', pair = (2, 2), ''
==================================================================
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/64140] match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match
2014-12-01 17:35 [Bug libstdc++/64140] New: match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match kariya_mitsuru at hotmail dot com
@ 2014-12-04 4:25 ` timshen at gcc dot gnu.org
2014-12-06 11:32 ` timshen at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: timshen at gcc dot gnu.org @ 2014-12-04 4:25 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140
--- Comment #1 from Tim Shen <timshen at gcc dot gnu.org> ---
Author: timshen
Date: Thu Dec 4 04:25:12 2014
New Revision: 218340
URL: https://gcc.gnu.org/viewcvs?rev=218340&root=gcc&view=rev
Log:
PR libstdc++/64140
* include/bits/regex.tcc (regex_iterator<>::operator++): Update
prefix.matched after modifying prefix.first.
* testsuite/28_regex/iterators/regex_iterator/char/64140.cc: New
testcase.
Added:
trunk/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/64140.cc
Modified:
trunk/libstdc++-v3/ChangeLog
trunk/libstdc++-v3/include/bits/regex.tcc
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/64140] match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match
2014-12-01 17:35 [Bug libstdc++/64140] New: match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match kariya_mitsuru at hotmail dot com
2014-12-04 4:25 ` [Bug libstdc++/64140] " timshen at gcc dot gnu.org
@ 2014-12-06 11:32 ` timshen at gcc dot gnu.org
2015-03-09 6:47 ` timshen at gcc dot gnu.org
2023-07-20 11:39 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: timshen at gcc dot gnu.org @ 2014-12-06 11:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140
--- Comment #2 from Tim Shen <timshen at gcc dot gnu.org> ---
Author: timshen
Date: Sat Dec 6 11:32:21 2014
New Revision: 218445
URL: https://gcc.gnu.org/viewcvs?rev=218445&root=gcc&view=rev
Log:
PR libstdc++/64140
Backport form mainline
2014-12-04 Tim Shen <timshen@google.com>
* include/bits/regex.tcc (regex_iterator<>::operator++): Update
prefix.matched after modifying prefix.first.
* testsuite/28_regex/iterators/regex_iterator/char/64140.cc: New
testcase.
Added:
branches/gcc-4_9-branch/libstdc++-v3/testsuite/28_regex/iterators/regex_iterator/char/64140.cc
Modified:
branches/gcc-4_9-branch/libstdc++-v3/ChangeLog
branches/gcc-4_9-branch/libstdc++-v3/include/bits/regex.tcc
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/64140] match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match
2014-12-01 17:35 [Bug libstdc++/64140] New: match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match kariya_mitsuru at hotmail dot com
2014-12-04 4:25 ` [Bug libstdc++/64140] " timshen at gcc dot gnu.org
2014-12-06 11:32 ` timshen at gcc dot gnu.org
@ 2015-03-09 6:47 ` timshen at gcc dot gnu.org
2023-07-20 11:39 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: timshen at gcc dot gnu.org @ 2015-03-09 6:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140
Tim Shen <timshen at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |FIXED
--- Comment #3 from Tim Shen <timshen at gcc dot gnu.org> ---
Resolved.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug libstdc++/64140] match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match
2014-12-01 17:35 [Bug libstdc++/64140] New: match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match kariya_mitsuru at hotmail dot com
` (2 preceding siblings ...)
2015-03-09 6:47 ` timshen at gcc dot gnu.org
@ 2023-07-20 11:39 ` redi at gcc dot gnu.org
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2023-07-20 11:39 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target Milestone|--- |4.9.3
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-07-20 11:39 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-01 17:35 [Bug libstdc++/64140] New: match_results.prefix() returns an incorrect result if regex_iterator holds a zero-length match kariya_mitsuru at hotmail dot com
2014-12-04 4:25 ` [Bug libstdc++/64140] " timshen at gcc dot gnu.org
2014-12-06 11:32 ` timshen at gcc dot gnu.org
2015-03-09 6:47 ` timshen at gcc dot gnu.org
2023-07-20 11:39 ` 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).