boostorg / spirit

Boost.org spirit module
http://boost.org/libs/spirit
394 stars 162 forks source link

compile error when using error_handler together with x3::variant #750

Open zhuoqiang opened 1 year ago

zhuoqiang commented 1 year ago

not sure why but if used together with x3::variant in one compilation unit in g++ 11.3, there is a weird compile error:

boost/spirit/home/x3/support/ast/variant.hpp: In instantiation of 'struct boost::spirit::x3::variant<>':
/my/src/parser.hpp:173:33:   required from here
boost/spirit/home/x3/support/ast/variant.hpp:131:15: error: wrong number of template arguments (0, should be at least 1)
  131 |         using variant_type = boost::variant<Types...>;
      |               ^~~~~~~~~~~~

boost/variant/variant_fwd.hpp:282:53: note: provided for 'template<class T0, class ... TN> class boost::variant'
  282 | template < BOOST_VARIANT_AUX_DECLARE_PARAMS > class variant;
      |                                                     ^~~~~~~

could be workaround by change the error_reporting.hpp

// typedef typename std::iterator_traits<Iterator>::value_type char_type;
// std::basic_string<char_type> line{start, end};
std::string line{start, end}; //
err_out << x3::to_utf8(line) << std::endl;

or replace the std::endl to '\n'

typedef typename std::iterator_traits<Iterator>::value_type char_type;
std::string line{start, end};
err_out << x3::to_utf8(line) << '\n';

here I propose we replace the std::endl with '\n' to avoid hitting potential compile bug