boostorg/spirit

`{qi,karma}::symbols` copy constructor does not make an independent copy

jwwalker opened this issue · 2 comments

In Boost 1.82.0 beta 1, the following code

#include <boost/spirit/include/qi.hpp>
#include <iostream>

int main(int argc, const char * argv[])
{
	boost::spirit::qi::symbols<char, int>	one;
	one.at("x") = 1;
	one.at("y") = 2;

	boost::spirit::qi::symbols<char, int>	two( one );
	two.at("x") = 3;
	
	std::cout << "In one, x = " << one.at("x") <<
		", y = " << one.at("y") << std::endl;
	
	return 0;
}

outputs "In one, x = 3, y = 2". I don't think anyone would expect a change to the copy to affect the original. If I instead default-construct two and then do a copy assignment two = one, things behave as expected.

It is might be in 'fix and find out' area because proto::deep_copy/BOOST_AUTO/qi::auto will start to do an actual copy then.

A workaround:

    boost::spirit::qi::symbols<char, int>    two;
    two = one;