I have a very simple parser rule (for AXE), like this:
auto space = axe::r_lit(' ');
auto spaces = space & space & space;
The last line compiles and works as expected in VC2010, but gives a strange error in 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
I wonder, whether it's a (known) bug in gcc, and whether it's even possible to get conversion errors with auto
declaration. Shouldn't the deduced type for auto
be always exactly the same type as the initializer?
AXE overloads operator& like this:
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));
}
I wasn't able to reduce the problem to a short test case, unfortunately every time I try to come with simple example, it compiles.
auto
variable, or if it is one of the&
operators having a problem with a temporary?auto
, because this line:space & space & space;
compiles without problems. Looking at the error message, compiler correctly identified the right side type, but for some reason decided to assignauto
a different type, which resulted in conversion error.auto
, but with the fact thatR1
in your second&
-use (E & space
, whereE
is the rvalue result of the first&
use) seems to be aT&
, instead of aT
(as required by C++0x). Smells like a GCC problem to me, right now.auto
?auto
, I think. It's with a mismatch between the type of the return expression and the return type of the second instantiation ofoperator&
. But that indicates thatR1
would be a different type in the body ofoperator&
than in the declaration section. Does it make a difference if you changeoperator&
to use theauto name() -> ...
notation? Just guessing...