Skip to content

boost::regex_match should delete the rvalue reference overload #257

@supernun

Description

@supernun

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:

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.

BOOST_REGEX_MODULE_EXPORT template <class ST, class SA, class Allocator, class charT, class traits>
inline bool regex_match(std::basic_string<charT, ST, SA>&&, 
                 match_results<typename std::basic_string<charT, ST, SA>::const_iterator, Allocator>& m, 
                 const basic_regex<charT, traits>& e, 
                 match_flag_type flags = match_default) = delete;

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions