I have following code:
#include <type_traits>
struct TType
{
int a = 0;
bool operator() (int&)
{
return true;
}
};
int main()
{
static_assert(std::is_same<decltype(std::declval<TType>()(std::declval<int>())), bool>::value, "wtf?");
return 0;
}
If I try to compile it with g++-4.8.2 then I receive an error:
main.cpp:321:82: error: no match for call to ‘(JetPlane) (int)’
static_assert(std::is_same<decltype(std::declval<JetPlane>()(std::declval<int>())), bool>::value, "wtf?");
^
main.cpp:265:8: note: candidate is:
struct JetPlane
^
main.cpp:279:7: note: bool JetPlane::operator()(int&)
bool operator() (int&)
^
main.cpp:279:7: note: no known conversion for argument 1 from ‘int’ to ‘int&’
I don't understand note: no known conversion for argument 1 from ‘int’ to ‘int&’
line. So the question is: why g++ interprets return type of std::declval<int>()
like int
and not line int&&
though std::declval declaration looks like:
template< class T >
typename std::add_rvalue_reference<T>::type declval();
I understand that it's prohibited to bind int&&
to int
. But why then compiler doesn't print: note: no known conversion for argument 1 from ‘int’ to ‘int&’
line. May be I don't understand something and compiler changes somehow return type of std::declval<int>()
from int&&
on int
in std::declval<TType>()(std::declval<int>())
?
Thank you for help!