boost-spirit-qi

ASAN stack-use-after-scope finding - when using parser with wrapped rule + auto keyword


complex but perfectly working grammar

my_grammar<It> grammar;

Test

using grammar direct --> NO ASAN finding

ok = qi::phrase_parse( f, l, qi::eps > grammar > qi::eoi, Skipper{}, v );

using a grammar "wrapper" --> ASAN Finding: stack-use-after-scope

auto grammar_wrapper = qi::eps > grammar > qi::eoi;

ok = qi::phrase_parse( f, l, grammar_wrapper, Skipper{}, v );

i have a problem to understand what type auto grammar_wrapper gets and why this type leads to an stack-user-after-scope


Solution

  • So... don't use the auto keyword.

    If you must, combat dangling references by doing a boost::proto::deep_copy of the parser expressions involved. There's a convenient short-hand in recent versions of Spirit Qi: qi::copy:

    auto grammar_wrapper = qi::copy ( qi::eps > grammar > qi::eoi );
    

    Background: