std::regex: inserting std::wregex to std::vector loses some std::wregex values

Tim Shen timshen@google.com
Wed Sep 10 05:43:00 GMT 2014


On Sun, Sep 7, 2014 at 11:19 AM, Tim Shen <timshen@google.com> wrote:
> On Sun, Sep 7, 2014 at 10:30 AM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>> On 7 September 2014 15:15, Stefan Schweter wrote:
>>> Is this error known?
>>
>> No, I don't think we've seen this before. Please create a bug report,
>> following the instructions at https://gcc.gnu.org/bugs
>
> basic_regex has incorrect move constructor:
>
>       basic_regex(const basic_regex&& __rhs) noexcept
>       : _M_flags(__rhs._M_flags), _M_traits(__rhs._M_traits),
>         _M_automaton(std::move(__rhs._M_automaton))
>       { }
>
> Should be:
>       basic_regex(basic_regex&&) noexcept = default;

Actually it's more than the move constructor. This PR reveals a design
issue (sorry):

basic_regex::_M_automaton, which is a _NFA, stores *const references*
of the basic_regex::_M_traits. When basic_regex object moves, those
references become dangling.

To solve this problem, I'm proposing removing those references and
pass the traits object in every time they're called in regex_match,
regex_search, etc. This requires interface adjusts for _AnyMatcher,
_CharMatcher and _BracketMatcher.

Sorry about the mistake :(
Thanks :)


-- 
Regards,
Tim Shen



More information about the Libstdc++ mailing list