boostorg / boostorg/regex

boost::regex_match should delete the rvalue reference overload

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

Description

https://github.com/boostorg/regex/blob/develop/include/boost/regex/v5/regex_match.hpp#L65

The const-ref overload gets picked up in this code-snippet:

```cpp
std::string GetStr();

boost::smatch m;
if (boost::regex_match(GetStr(), m, boost::regex{"f(o)o"}) {
m.str(1); // dangling reference
}
```

Issue sneaks up on you when `GetStr` used to return a `const std::string &` but now returns it by value.

Notably: the std::regex implementation deletes the rvalue reference overload: https://en.cppreference.com/w/cpp/regex/regex_match.html

Boost should probably do the same here.

```cpp
BOOST_REGEX_MODULE_EXPORT template
inline bool regex_match(std::basic_string&&,
match_results::const_iterator, Allocator>& m,
const basic_regex& e,
match_flag_type flags = match_default) = delete;
```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in include/boost/regex/v5/regex_match.hpp at the cited overload and compare its behavior with the std::regex rvalue-reference overload. Confirm that the provided temporary-string example cannot select the unsafe overload, and verify the existing regex functionality remains intact.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.