2

Trying to compile the following code (a minimal example created from my original code) gives the error listed below.

The problem seems to be with the line qi::phrase_parse(first, str.end(), grammar, ascii::blank);, but I have no clue what could be wrong with this. Removing that line causes the code to compile successfully, so it seems there is nothing wrong with the grammar definition itself.

This SO question reports a similar error, but I can't find anything applicable in the answer.

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

using namespace std;
namespace qi = boost::spirit::qi;
namespace ascii = boost::spirit::ascii;

template <typename Iterator>
class DoubleGrammar : qi::grammar<Iterator, ascii::blank_type> {
private:
    qi::rule<Iterator, ascii::blank_type> double_rule;
public:
    DoubleGrammar() : DoubleGrammar::base_type(double_rule) {
        double_rule = qi::double_;
    }
};

int main(int argc, char** argv) {
    DoubleGrammar<string::iterator> grammar;
    string str = "1.0";
    string::iterator first = str.begin();
    qi::phrase_parse(first, str.end(), grammar, ascii::blank);
    return 0;
}

Compiler output:

In file included from /usr/include/boost/proto/traits.hpp:24:0,
                 from /usr/include/boost/proto/expr.hpp:27,
                 from /usr/include/boost/proto/core.hpp:17,
                 from /usr/include/boost/proto/proto.hpp:12,
                 from /usr/include/boost/spirit/home/support/meta_compiler.hpp:19,
                 from /usr/include/boost/spirit/home/qi/meta_compiler.hpp:14,
                 from /usr/include/boost/spirit/home/qi/action/action.hpp:14,
                 from /usr/include/boost/spirit/home/qi/action.hpp:14,
                 from /usr/include/boost/spirit/home/qi.hpp:14,
                 from /usr/include/boost/spirit/include/qi.hpp:16,
                 from .build/test/spirittest.cpp:4:
/usr/include/boost/spirit/home/qi/detail/parse.hpp: In instantiation of 'struct boost::spirit::qi::detail::phrase_parse_impl<DoubleGrammar<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >, void>':
/usr/include/boost/spirit/home/qi/detail/parse_auto.hpp:186:50:   required from 'bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, Expr&, const Skipper&, boost::spirit::qi::skip_flag) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; Expr = DoubleGrammar<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >; Skipper = boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::blank, boost::spirit::char_encoding::ascii> >, 0l>]'
.build/test/spirittest.cpp:62:61:   required from here
/usr/include/boost/spirit/home/qi/detail/parse.hpp:59:9: error: static assertion failed: error_invalid_expression
         BOOST_SPIRIT_ASSERT_MATCH(qi::domain, Expr);
         ^
In file included from /usr/include/boost/spirit/home/qi/auto.hpp:16:0,
                 from /usr/include/boost/spirit/home/qi.hpp:15,
                 from /usr/include/boost/spirit/include/qi.hpp:16,
                 from .build/test/spirittest.cpp:4:
/usr/include/boost/spirit/home/qi/detail/parse_auto.hpp: In instantiation of 'bool boost::spirit::qi::phrase_parse(Iterator&, Iterator, Expr&, const Skipper&, boost::spirit::qi::skip_flag) [with Iterator = __gnu_cxx::__normal_iterator<char*, std::basic_string<char> >; Expr = DoubleGrammar<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >; Skipper = boost::proto::exprns_::expr<boost::proto::tagns_::tag::terminal, boost::proto::argsns_::term<boost::spirit::tag::char_code<boost::spirit::tag::blank, boost::spirit::char_encoding::ascii> >, 0l>]':
.build/test/spirittest.cpp:62:61:   required from here
/usr/include/boost/spirit/home/qi/detail/parse_auto.hpp:186:50: error: 'call' is not a member of 'boost::spirit::qi::detail::phrase_parse_impl<DoubleGrammar<__gnu_cxx::__normal_iterator<char*, std::basic_string<char> > >, void>'
             first, last, expr, skipper, post_skip);
                                                  ^
Community
  • 1
  • 1
Oebele
  • 581
  • 1
  • 4
  • 17
  • I just tested, `cv_and_he`'s comment is the answer. The code compiles and runs after that is fixed. – Chris Beck Mar 14 '16 at 21:25
  • @cv_and_he can you please adhere to SO etiquette and post answers as answers? It's really quite annoying that none of these questions ever seem to get accepted answers this way. – sehe Mar 14 '16 at 22:09
  • @sehe Sure, from now on I won't post answers in comments. – llonesmiz Mar 15 '16 at 01:55

1 Answers1

2

I actually found the answer with the help of this SO answer I found in the related questions list.

The problem was that the DoubleGrammar class inherited qi::grammar privately. Adding a public visibility specifier solved the problem.

This went wrong because the example on which it was based used a struct, which has public visibility by default.

Community
  • 1
  • 1
Oebele
  • 581
  • 1
  • 4
  • 17