Opened 11 years ago

Closed 11 years ago

#6343 closed Bugs (invalid)

Spirit::qi semantic action destroys attribute value

Reported by: kkanishev@… Owned by: Joel de Guzman
Milestone: To Be Determined Component: spirit
Version: Boost 1.48.0 Severity: Problem
Keywords: Cc:

Description

Long story short. This code:

#include <boost/config/warning_disable.hpp>
#include <boost/spirit/include/qi.hpp>
#include <boost/foreach.hpp>

#include <iostream>
#include <string>
#include <vector>

void f(){return;}

int main()
{
        namespace qi = boost::spirit::qi;
        namespace ns = boost::spirit::ascii;

        qi::rule<std::string::iterator,std::vector<int>(),ns::space_type>  ex;
        ex =  qi::int_[f] >> *ex;

        std::string str = "3 1 4 1 5 9";
        std::vector<int> out;

        if(qi::phrase_parse(str.begin(),str.end(),ex,ns::space,out))
        {
                std::cout << "Result: ";
                BOOST_FOREACH(int d , out) std::cout << d << " , ";
                std::cout << "\n";
        }
}

Doesn't change the contents of the "std::vector<int> out".

If I remove the semantic action: ex = qi::int_ >> *ex;

Then everything goes as expected.

Change History (1)

comment:1 by Joel de Guzman, 11 years ago

Resolution: invalid
Status: newclosed

When a semantic action is present anywhere in a rule, automatic attribute propagation is disabled. If you want to force attribute propagation, you can use the %= operator:

ex %= qi::int_[f] >> *ex;

BTW, the proper forum for support is the Spirit mailing lists: http://boost-spirit.com/home/feedback-and-support/. Please ask the list first before flagging this as a bug here.

Note: See TracTickets for help on using tickets.