我有一个非常简单的解析器规则(对于AX),如下所示:
auto space = axe::r_lit(' ');
auto spaces = space & space & space;
Run Code Online (Sandbox Code Playgroud)
最后一行在VC2010中编译并按预期工作,但在gcc 4.6中给出了一个奇怪的错误:
parsers.cpp:68:34: error: conversion from
'axe::r_and_t<
axe::r_and_t<axe::r_char_t<char>&, axe::r_char_t<char>&>,
axe::r_char_t<char>&
>' to non-scalar type
'axe::r_and_t<
axe::r_and_t<axe::r_char_t<char>&, axe::r_char_t<char>&>&,
axe::r_char_t<char>&
>' requested
Run Code Online (Sandbox Code Playgroud)
我想知道,它是否是gcc中的(已知)错误,以及是否有可能通过auto声明获得转换错误.推导出的类型不auto应该总是与初始化器完全相同吗?
AX 重载运算符&像这样:
template<class R1, class R2>
r_and_t<
typename std::enable_if<
is_rule<typename std::remove_reference<R1>::type>::value, R1>::type,
typename std::enable_if<
is_rule<typename std::remove_reference<R2>::type>::value, R2>::type
>
operator& (R1&& r1, R2&& r2)
{
return r_and_t<R1, R2>(std::forward<R1>(r1), std::forward<R2>(r2));
}
Run Code Online (Sandbox Code Playgroud)
我无法将问题简化为一个简短的测试用例,不幸的是每次我尝试用简单的例子来编译它.
问题出在参考文献中。
parsers.cpp:68:34: error: conversion from
'axe::r_and_t<
axe::r_and_t<axe::r_char_t<char>&, axe::r_char_t<char>&>,
axe::r_char_t<char>&
>' to non-scalar type
'axe::r_and_t<
axe::r_and_t<axe::r_char_t<char>&, axe::r_char_t<char>&>&,
axe::r_char_t<char>&
>' requested
Run Code Online (Sandbox Code Playgroud)
第一个模板参数axe::r_and_t<axe::r_char_t<char>&, axe::r_char_t<char>&>用于第一个模板参数,第二个模板axe::r_and_t<axe::r_char_t<char>&, axe::r_char_t<char>&>&参数用于第二个模板参数。这是模板参数不匹配——可能在返回值中。最有可能的是,发生这种情况是因为 Visual Studio 的 SFINAE 实现充其量是不可靠的,并且它没有正确实现两阶段查找,并且 GCC 版本可能选择了与 Visual Studio 不同的重载。