Describe the bug
N5032 [re.alg.match]/2-3 specify for regex_match():
Effects: Determines whether there is some sub-sequence within [first, last) that matches the regular expression e. [...] Returns true if such a sequence exists, false otherwise.
Postconditions: m.ready() == true in all cases. If the function returns false, then the effect on [match_results] parameter m is unspecified except that m.size() returns 0 and m.empty() returns true.
Furthermore, the default constructor of basic_regex satisfies the following postcondition [re.regex.construct]/1:
Postconditions: *this does not match any character sequence.
This means that m.ready() should be true and m.size() should be 0 for argument m when regex_match() is called on a default-constructed basic_regex, but the current implementation fails to adjust the match_results internals accordingly.
Similar behavior is specified for regex_search().
Test case
#include <iostream>
#include <regex>
#include <string>
using namespace std;
int main() {
const string input = "abc";
{
smatch sm;
regex re;
regex_match(input, sm, re);
cout << "match_results ready: " << sm.ready() << '\n';
cout << "match_results size: " << sm.size() << '\n';
}
{
smatch sm;
regex re;
regex re2("abc");
regex_match(input, sm, re2);
regex_match(input, sm, re);
cout << "match_results ready: " << sm.ready() << '\n';
cout << "match_results size: " << sm.size() << '\n';
}
}
This program currently prints:
match_results ready: 0
match_results size: 0
match_results ready: 1
match_results size: 1
https://godbolt.org/z/5j543r517 (which also shows that the same bug is present in libstdc++)
Expected behavior
The program should print (as it does using libc++):
match_results ready: 1
match_results size: 0
match_results ready: 1
match_results size: 0
Describe the bug
N5032 [re.alg.match]/2-3 specify for
regex_match():Furthermore, the default constructor of
basic_regexsatisfies the following postcondition [re.regex.construct]/1:This means that
m.ready()should betrueandm.size()should be0for argumentmwhenregex_match()is called on a default-constructedbasic_regex, but the current implementation fails to adjust thematch_resultsinternals accordingly.Similar behavior is specified for
regex_search().Test case
This program currently prints:
https://godbolt.org/z/5j543r517 (which also shows that the same bug is present in libstdc++)
Expected behavior
The program should print (as it does using libc++):