I applied an example from x3 documentation ( http://ciere.com/cppnow15/x3_docs/spirit/tutorials/rexpr.html ) to parse a simple binary prefix notation grammar, and I found that I needed to define a copy command, assign copy to op and the default constructor when compiling with g ++ 6.1.1, despite the example requiring that you only need to add constructors base_typeand assign operators using using. Then I came across the fact that it compiles, as expected, with clang 3.8.1. I will write an important part of the code, and here is a complete example for g ++ with an AST printer that shows an error.
I see that g ++ seems to think that the con copy was deleted because a move constructor or move destination statement was defined, but then why does it compile with clang? Which compiler is right?
#include <iostream>
#include <string>
#include <vector>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/ast/variant.hpp>
namespace x3 = boost::spirit::x3;
namespace chars = boost::spirit::x3::ascii;
namespace ast {
struct Expression;
struct Primary : x3::variant<
std::string,
x3::forward_ast<Expression>
> {
Primary& operator=(const Primary&) = default;
Primary(const Primary&) = default;
Primary() = default;
using base_type::base_type;
using base_type::operator=;
};
using ArgumentList = std::vector<Primary>;
struct Expression {
std::string func_name;
ArgumentList arguments;
Expression() : func_name(), arguments() { }
};
}
BOOST_FUSION_ADAPT_STRUCT(
ast::Expression,
func_name,
arguments
)
namespace parser {
x3::rule<class Primary, ast::Primary > Primary = "Primary";
x3::rule<class Expression, ast::Expression > Expression = "Expression";
const auto function_name = x3::lexeme[ +chars::alnum ];
const auto number = x3::lexeme[ +chars::digit ];
const auto Primary_def = number | Expression;
const auto Expression_def = function_name > x3::repeat(2)[ Primary ];
BOOST_SPIRIT_DEFINE(Primary, Expression)
}
int main() {
while (std::cin.good() == true) {
const auto line = [&]() {
std::string str;
std::getline(std::cin, str);
return str;
}();
auto iter_in_line = begin(line);
const auto end_of_line = end(line);
ast::Expression root_expr;
const bool is_match = phrase_parse(iter_in_line, end_of_line,
parser::Expression,
chars::space,
root_expr
);
}
}
source
share