segfault with nested, adapted, structs
David Mugnai <[email protected]>
| Newsgroups | gmane.comp.parsers.spirit.general |
|---|---|
| Message-ID | <[email protected]> |
The following reduced test case segfaults when used with the spirit
version shipped with boost 1.64.
I'm using gcc 7.1.0: g++ test.cpp && ./a.out
If I remove BOOST_SPIRIT_X3_DEBUG the program does not segfault anymore.
As a workaround I found that the alternative definition of test prevents
the crash.
david
======================================================================
#define BOOST_SPIRIT_X3_DEBUG
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/spirit/home/x3.hpp>
#include <string>
namespace x3 = boost::spirit::x3;
struct c8 {
uint8_t x;
uint8_t y;
};
struct c16 {
uint16_t x;
uint16_t y;
};
struct r {
c8 a;
c16 b;
};
BOOST_FUSION_ADAPT_STRUCT(c8, x, y)
BOOST_FUSION_ADAPT_STRUCT(c16, x, y)
BOOST_FUSION_ADAPT_STRUCT(r, a, b)
x3::rule<class c8_, c8> pc8 = "C8";
const auto pc8_def = x3::uint8 >> ',' >> x3::uint8;
x3::rule<class c16_, c16> pc16 = "C16";
const auto pc16_def = x3::uint16 >> ',' >> x3::uint16;
x3::rule<class test_, r> test = "TEST";
const auto test_def = "TEST" >> pc8 >> pc16;
// uncomment to workaround
//const auto test_def = "TEST" >> x3::lexeme[pc8] >> x3::lexeme[pc16];
BOOST_SPIRIT_DEFINE(pc8, pc16, test);
int main() {
std::string input{"TEST 1,1 500,100"};
r out;
x3::phrase_parse(begin(input), end(input), test, x3::ascii::space, out);
}
======================================================================
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot