Skip to content

Commit bbc5144

Browse files
author
Andreas Buhr
committed
Reproducer for another variant of Github Issue 279.
Again, a produced result is later overwritten by a parser producing a nope.
1 parent d873d7e commit bbc5144

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed

test/github_issues.cpp

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,54 @@ void github_issue_279()
361361
BOOST_TEST(!condition.has_value());
362362
}
363363

364+
namespace github_issue_286_ {
365+
namespace bp = boost::parser;
366+
367+
struct Content
368+
{
369+
~Content()
370+
{
371+
int setbreakpointhere = 0;
372+
}
373+
};
374+
constexpr bp::rule<struct content_tag, std::shared_ptr<Content>> content = "content";
375+
constexpr auto content_action = [](auto& ctx) {
376+
std::shared_ptr<Content>& result = _val(ctx);
377+
result = std::make_shared<Content>();
378+
};
379+
constexpr auto content_def = (bp::lit(U"content") >> bp::eol)[content_action];
380+
BOOST_PARSER_DEFINE_RULES(content);
381+
382+
}
383+
384+
void github_issue_286()
385+
{
386+
using namespace github_issue_286_;
387+
namespace bp = boost::parser;
388+
389+
constexpr auto prolog = bp::lit(U"prolog") >> bp::eol;
390+
391+
constexpr auto epilog =
392+
bp::no_case[bp::lexeme[bp::lit(U"epi") >> bp::lit(U"log")]]
393+
>> bp::eol;
394+
395+
constexpr auto full_parser = prolog >> content >> epilog;
396+
397+
std::u8string teststring =
398+
u8""
399+
"prolog\n"
400+
"content\n"
401+
"epilog\n"
402+
;
403+
404+
// "content" produces a shared_ptr with the result.
405+
// The "epilog" parser must not delete the result.
406+
407+
auto const result = bp::parse(teststring, full_parser, bp::blank);
408+
BOOST_TEST(result);
409+
BOOST_TEST(result.value().get() != nullptr);
410+
}
411+
364412

365413
int main()
366414
{
@@ -374,5 +422,6 @@ int main()
374422
github_issue_223();
375423
github_issue_248();
376424
github_issue_279();
425+
github_issue_286();
377426
return boost::report_errors();
378427
}

0 commit comments

Comments
 (0)