<html>
<head>
<base href="http://llvm.org/bugs/" />
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW --- - regex iterator endless loop"
href="http://llvm.org/bugs/show_bug.cgi?id=21751">21751</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>regex iterator endless loop
</td>
</tr>
<tr>
<th>Product</th>
<td>libc++
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</td>
</tr>
<tr>
<th>Hardware</th>
<td>Macintosh
</td>
</tr>
<tr>
<th>OS</th>
<td>All
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>All Bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu, mclow.lists@gmail.com
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Given the following 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;
}
}
----
The loop runs forever.
Suggested output from <<a href="https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140">https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64140</a>>:
----
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), ''
----
Thanks to Jonathan Wakely for the report.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>