Я сталкиваюсь с частыми segfaults с моим парсером Spirit Qi.
Потратив несколько дней на отладку проблемы (я обнаружил, что трассировку стека невозможно найти), я решил сократить ее до минимального примера. Может ли кто-нибудь сказать, что я делаю неправильно, если что?
Сохраните код как bug.cpp, скомпилируйте с помощью g++ -Wall -o bug bug.cpp
, и все готово.
//#define BOOST_SPIRIT_DEBUG_PRINT_SOME 80
//#define BOOST_SPIRIT_DEBUG
#include <boost/spirit/version.hpp>
#include <boost/spirit/include/qi.hpp>
#include <iostream>
#include <fstream>
#include <iterator>
#include <string>
namespace /*anon*/
{
using namespace boost::spirit::qi;
template <typename Iterator, typename
Skipper> struct bug_demo :
public grammar<Iterator, Skipper>
{
bug_demo() :
grammar<Iterator, Skipper>(story, "bug"),
story(the),
the("the")
{
// BOOST_SPIRIT_DEBUG_NODE(story);
// BOOST_SPIRIT_DEBUG_NODE(the);
}
rule<Iterator, Skipper> story, the;
};
template <typename It>
bool do_parse(It begin, It end)
{
bug_demo<It, space_type> grammar;
return phrase_parse(begin, end, grammar, space);
}
}
int main()
{
std::cout << "Spirit version: " << std::hex << SPIRIT_VERSION << std::endl;
try
{
std::string contents = "the lazy cow";
if (do_parse(contents.begin(), contents.end()))
return 0;
} catch (std::exception e)
{
std::cerr << "exception: " << e.what() << std::endl;
}
return 255;
}
Я тестировал это с
- g++ 4.4, 4.5, 4.6 и
- версии boost 1.42 (ubuntu meerkat) и 1.46.1.1 (natty)
Выход
sehe@meerkat:/tmp$ ./bug
Spirit version: 2020
Segmentation fault
Или, с повышением 1.46.1, он сообщит Spirit version: 2042
story
передthe
; почему вы ожидаете, что это сработает? Попробуйтеrule<Iterator, Skipper> the, story;
. - person ildjarn   schedule 14.05.2011