boostorg / spirit

Boost.org spirit module
http://boost.org/libs/spirit
392 stars 161 forks source link

msvc-14.0 error C2039: 'on_success': is not a member of ... #311

Closed octopus-prime closed 6 years ago

octopus-prime commented 6 years ago

Compiling this code with msvc-14.0:

#include <boost/detail/lightweight_test.hpp>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/utility/error_reporting.hpp>
#include <string>
#include <sstream>

namespace x3 = boost::spirit::x3;

struct error_handler_base
{
    template <typename Iterator, typename Exception, typename Context>
    x3::error_handler_result on_error(
        Iterator& first, Iterator const& last
      , Exception const& x, Context const& context)
    {
        std::string message = "Error! Expecting: " + x.which() + " here:";
        auto& error_handler = x3::get<x3::error_handler_tag>(context).get();
        error_handler(x.where(), message);
        return x3::error_handler_result::fail;
    }
};

struct test_rule_class : error_handler_base {};

x3::rule<test_rule_class> const test_rule;
auto const test_rule_def = x3::lit("foo") > x3::lit("bar") > x3::lit("git");

BOOST_SPIRIT_DEFINE(test_rule);

void test(std::string const& line_break) {
    std::string const input("foo" + line_break + "  foo" + line_break + "git");
    auto const begin = std::begin(input);
    auto const end = std::end(input);

    std::stringstream stream;
    x3::error_handler<std::string::const_iterator> const error_handler{begin, end, stream};

    auto const parser = x3::with<x3::error_handler_tag>(std::ref(error_handler))[test_rule];
    x3::phrase_parse(begin, end, parser, x3::space);

    BOOST_TEST_EQ(stream.str(), "In line 2:\nError! Expecting: \"bar\" here:\n  foo\n__^_\n");
}

int main() {
    test("\n");
    test("\r");
    test("\r\n");

    return boost::report_errors();
}

leads to this error messages:


error_handler.cpp
.\boost/spirit/home/x3/nonterminal/detail/rule.hpp(174): error C2039: 'on_success': is not a member of 'test_rule_class'
libs\spirit\test\x3\error_handler.cpp(29): note: see declaration of 'test_rule_class'
.\boost/spirit/home/x3/nonterminal/detail/rule.hpp(220): note: see reference to function template instantiation 'bool boost::spirit::x3::detail::rule_parser<boost::spirit::x3::unused_type,ID>::call_on_success<Iterator,Context,ActualAttribute>(Iterator &,const Iterator &,const Context &,ActualAttribute &,boost::mpl::true_)' being compiled
        with
        [
            ID=test_rule_class,
            Iterator=std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::error_handler_tag,std::reference_wrapper<const boost::spirit::x3::error_handler<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>>,boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::standard::space_type,boost::spirit::x3::unused_type>>,
            ActualAttribute=transform_attr
        ]
.\boost/spirit/home/x3/nonterminal/detail/rule.hpp(219): note: see reference to function template instantiation 'bool boost::spirit::x3::detail::rule_parser<boost::spirit::x3::unused_type,ID>::call_on_success<Iterator,Context,ActualAttribute>(Iterator &,const Iterator &,const Context &,ActualAttribute &,boost::mpl::true_)' being compiled
        with
        [
            ID=test_rule_class,
            Iterator=std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>,
            Context=boost::spirit::x3::context<boost::spirit::x3::error_handler_tag,std::reference_wrapper<const boost::spirit::x3::error_handler<std::_String_const_iterator<std::_String_val<std::_Simple_types<char>>>>>,boost::spirit::x3::context<boost::spirit::x3::skipper_tag,const boost::spirit::x3::standard::space_type,boost::spirit::x3::unused_type>>,
            ActualAttribute=transform_attr
        ]
... [cut]

All other tests compile fine... Does somebody know a workaround for this error? Is x3 designated to compile with msvc-14.0?

djowel commented 6 years ago

Man, I always forget which is which! Is msvc-14.0 VS2015?

octopus-prime commented 6 years ago

In my opinion it's VS2015.

djowel commented 6 years ago

IIRC, @Kojoley had some recent workarounds for VS2015, but I'm not sure if you got it yet, nor do I know about its effectivity.

octopus-prime commented 6 years ago

This is better:

struct test_rule_class : x3::annotate_on_success, error_handler_base {};
...
x3::error_handler<std::string::const_iterator> error_handler{begin, end, stream};

instead of:

struct test_rule_class : error_handler_base {};
...
x3::error_handler<std::string::const_iterator> const error_handler{begin, end, stream};

No idea why msvc-14.1, gcc-7 and clang-5.0 build the "buggy" version...