boostorg / boostorg/regex

boost::regex_search contradicts std::regex_search in changing match_result argument

Open
#68 1 comment 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
119
Forks
113
PR merge metrics
No merged PRs in 30d

Description

```
#include
#include
#include
#include

std::string target("821-xxxzzz");
void st() {
std::smatch sm;
std::regex re1("^.+\\/(\\d+)$");
std::regex_search(target, sm, re1);
std::cout << "after std search, smatch is " << sm.size() << std::endl;
}
void bst() {
boost::smatch sm;
boost::regex re1("^.+\\/(\\d+)$");
boost::regex_search(target, sm, re1);
std::cout << "after boost search, smatch is " << sm.size() << std::endl;
}

int main() {
st();
bst();
return 0;
}
```
```
after std search, smatch is 0
after boost search, smatch is 2
```
STD (cppreference.com) says:
`the object match is updated as follows: If the match does not exist: match.ready() == true; match.empty() == true; match.size() == 0`
While Boost docs says:
`Postconditions: If the function returns false, then the effect on parameter match is undefined`

This assumption contradicts with the logic and expectations of end-user, that if no match was found in text, then the `boost::match_result` object state would represent it through `empty` and `size` methods. Everything said is related to `boost::regex_match` too.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.