http://llvm.org/bugs/show_bug.cgi?id=22061
Bug ID: 22061
Summary: A match_results returns an incorrect sub_match if the
sub_match::matched is false
Product: libc++
Version: unspecified
Hardware: All
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: All Bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
Classification: Unclassified
Created attachment 13607
--> http://llvm.org/bugs/attachment.cgi?id=13607&action=edit
clang++ -v
Please see the following sample.
====================================== sample code
======================================
#include <iostream>
#include <regex>
int main()
{
const char s[] = "abc";
const std::regex re("(\\d+)|(\\w+)");
std::cmatch m;
std::regex_search(s, m, re);
std::cout << std::boolalpha;
for (size_t i = 0, n = m.size(); i < n; ++i) {
auto&& sub = m[i];
std::cout << i << ":" << sub.matched << ", str = '" << sub.str() << "',
"
"range = [" << sub.first - s << ", " << sub.second - s << ")" <<
std::endl;
}
}
=========================================================================================
============================= output =============================
0:true, str = 'abc', range = [0, 3)
1:false, str = '', range = [-4479204, -4479204)
2:true, str = 'abc', range = [0, 3)
==================================================================
cf. http://melpon.org/wandbox/permlink/42XecnPeRQGI1tAV
The C++11 standard 28.10[re.results]/p.4 says, "Otherwise matched is false, and
members first and second point to the end of the sequence that was searched."
So, I think that the output should be
============================= output =============================
0:true, str = 'abc', range = [0, 3)
1:false, str = '', range = [3, 3)
2:true, str = 'abc', range = [0, 3)
==================================================================
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs