Created on 2013-09-21.00:00:00 last changed 143 months ago
Proposed resolution:
This wording is relative to N3691.
Edit [re.syn], header <regex> synopsis, as indicated:
#include <initializer_list>
namespace std {
[…]
// 28.11.2, function template regex_match:
[…]
template <class ST, class SA, class Allocator, class charT, class traits>
bool regex_match(const basic_string<charT, ST, SA>&&,
match_results<
typename basic_string<charT, ST, SA>::const_iterator,
Allocator>&,
const basic_regex<charT, traits>&,
regex_constants::match_flag_type =
regex_constants::match_default) = delete;
// 28.11.3, function template regex_search:
[…]
template <class ST, class SA, class Allocator, class charT, class traits>
bool regex_search(const basic_string<charT, ST, SA>&&,
match_results<
typename basic_string<charT, ST, SA>::const_iterator,
Allocator>&,
const basic_regex<charT, traits>&,
regex_constants::match_flag_type =
regex_constants::match_default) = delete;
[…]
}
[ 2014-02-13 Issaquah: Move as Immediate ]
Consider the following code:
const regex r(R"(meow(\d+)\.txt)");
smatch m;
if (regex_match(dir_iter->path().filename().string(), m, r)) {
DoSomethingWith(m[1]);
}
This occasionally crashes. The problem is that dir_iter->path().filename().string() returns a temporary string, so the match_results contains invalidated iterators into a destroyed temporary string.
It's fine for regex_match/regex_search(str, reg) to accept temporary strings, because they just return bool. However, the overloads taking match_results should forbid temporary strings.| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2014-02-27 17:03:20 | admin | set | status: wp -> c++14 |
| 2014-02-20 13:52:38 | admin | set | status: immediate -> wp |
| 2014-02-14 07:07:05 | admin | set | messages: + msg6856 |
| 2014-02-14 07:07:05 | admin | set | status: new -> immediate |
| 2013-10-12 18:21:48 | admin | set | messages: + msg6725 |
| 2013-09-21 00:00:00 | admin | create | |