boostorg / boostorg/xpressive

Creation of self referencing regexp throws exception "bad regex reference"

Open
#8 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
19
Forks
40
PR merge metrics
No merged PRs in 30d

Description

Hi.
I'm trying to create composite regular expression by appending pieces one at a time.

Example:

```c++
#include

#include
#include

int main()
{
using namespace boost::xpressive;
using namespace std::string_literals;
auto regex = sregex{ bos >> as_xpr("foo") >> *_ };

regex = regex | sregex{ bos >> as_xpr("bar") >> *_ };

std::cout << regex_match("foololo"s, regex) << std::endl;
std::cout << regex_match("barlolo"s, regex) << std::endl;

return 0;
}
```

I get exception from ` regex = regex | sregex{ bos >> as_xpr("bar") >> *_ };`. It seems that inside of assignment it enters `boost::xpressive::detail::regex_matcher::static_compile_impl2(...)`, does `impl->tracking_clear();` and partially clears contents of the temporary object on the right hand side of assignment operator.

It seems to me that my case is pretty similar to the case described in the [Embedding a Regex by Value](http://www.boost.org/doc/libs/1_65_1/doc/html/xpressive/user_s_guide.html#boost_xpressive.user_s_guide.grammars_and_nested_matches.embedding_a_regex_by_value) example. I am able to reproduce this behavior for boost 1.65.1 and 1.66.0 on both MSVC 2015 sp1 with /std:c++=latest and gcc 7.2.0.

How should I create such composite regular expression assuming I don't have all the pieces at once?

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.