Re: Spirit X3 with on_success() calls on VS2015
Mikael Asplund <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
To follow up on this: Made a minimal example online (also attached): http://coliru.stacked-crooked.com/a/208eaadc853b0d6d This will on linux print: me: 1 x3: 1 real: 1 And on Windows: me: 1 x3: 0 real: 0 Really weird stuff... Regards, Mikael From: Mikael Asplund [mailto:[email protected]] Sent: Thursday, March 17, 2016 15:55 To: [email protected] Subject: [Spirit-general] Spirit X3 with on_success() calls on VS2015 Hi! I seem to have run into a bug in spirit x3 (or more likely in VS2015, but there is no workaround in spirit). I have a small unit test like this: struct XXX : x3::annotate_on_success {}; ... auto a = x3::detail::has_on_success<XXX, parser::iterator_type, x3::unused_type, ast::Identifier&>(); typedef decltype(XXX().on_success(std::declval<iterator_type&>(), std::declval<iterator_type>(), std::declval<ast::Identifier&>(), x3::unused)) type; bool b = a; ensure(b); ... This builds fine on both Linux (clang and g++) and Windows (VS2015 Update 1-2 CTP), but the test (ensure()) fails on Windows only. That the typedef builds fine would indicate to me that the method is there and should be no problem calling (and again, this builds fine in VS2015, too). However, has_on_success somehow fails to detect this in VS2015, but it works fine on Linux. This results in my on_success() not being called on Windows. I'm looking into this, but wanted to ask if someone have seen this before and is aware of this problem and why it occurs? Maybe someone with more knowledge is this area that can figure it out quickly? Regards, Mikael ------------------------------------------------------------------------------ Transform Data into Opportunity. Accelerate data analysis in your applications with Intel Data Analytics Acceleration Library. Click to learn more. http://pubads.g.doubleclick.net/gampad/clk?id=278785231&iu=/4140 _______________________________________________ Spirit-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/spirit-general
on_success.cpp
(text/plain, 2.2 KB)
#include <iostream>
#include <string>
#include <vector>
#include <boost/spirit/home/x3.hpp>
#include <boost/spirit/home/x3/support/utility/annotate_on_success.hpp>
using std::string;
using std::vector;
using std::pair;
namespace x3 = boost::spirit::x3;
namespace ast {
struct Identifier {};
}
typedef vector<string>::const_iterator iterator_type;
struct XXX : x3::annotate_on_success {};
template <typename Expr, typename T = void>
struct disable_if_substitution_failure {
typedef T type;
};
template <typename ID, typename Iterator, typename Attribute, typename Context, typename Enable = void>
struct my_has_on_success : boost::mpl::false_ {};
template <typename ID, typename Iterator, typename Attribute, typename Context>
struct my_has_on_success<ID, Iterator, Context, Attribute,
typename disable_if_substitution_failure<
decltype(
std::declval<ID>().on_success(
std::declval<Iterator&>()
, std::declval<Iterator>()
, std::declval<Attribute&>()
, std::declval<Context>()
)
)>::type
>
: boost::mpl::true_ {};
template <typename ID, typename Iterator, typename Attribute, typename Context, typename Enable = void>
struct x3_has_on_success : boost::mpl::false_ {};
template <typename ID, typename Iterator, typename Attribute, typename Context>
struct x3_has_on_success<ID, Iterator, Context, Attribute,
typename x3::disable_if_substitution_failure<
decltype(
std::declval<ID>().on_success(
std::declval<Iterator&>()
, std::declval<Iterator>()
, std::declval<Attribute&>()
, std::declval<Context>()
)
)>::type
>
: boost::mpl::true_ {};
int main() {
auto a1 = my_has_on_success<XXX, iterator_type, x3::unused_type, ast::Identifier&>();
auto a2 = x3_has_on_success<XXX, iterator_type, x3::unused_type, ast::Identifier&>();
auto a3 = x3::detail::has_on_success<XXX, iterator_type, x3::unused_type, ast::Identifier&>();
typedef decltype(XXX().on_success(std::declval<iterator_type&>(), std::declval<iterator_type>(), std::declval<ast::Identifier&>(), x3::unused)) type;
bool b1 = a1;
bool b2 = a2;
bool b3 = a3;
std::cout << "me: " << b1 << std::endl;
std::cout << "x3: " << b2 << std::endl;
std::cout << "real: " << b3 << std::endl;
return 0;
}