When attempting to use an rvalue reference, I get the following error from GCC (clang does not generate an error):
/usr/include/c++/8/istream:951:12: error: no match for ‘operator>>’ (operand types are ‘std::basic_istream<char>’ and ‘std::basic_istream<char>& (*)(std::basic_istream<char>&, std::__cxx11::basic_string<char>&)’)
The code I am trying to compile is:
typedef std::istream &getline_type(std::istream &, std::string &);
void operator>>(std::istream &, getline_type) {} // 1
void operator>>(std::istream &&, getline_type) {}
int main()
{
std::string s;
getline_type *getline = std::getline; // 2
//using std::getline; // 3
std::istringstream("a") >> getline;
}
If I comment out the line marked // 1
, it works.
If I use the line marked // 3
instead of // 2
, it also works.
Why is the compiler generating an error? Is it a bug in GCC?
I believe clang is correctly assessing that the code is well-formed, but if there is a valid reason to reject the code, it might indicate a bug in clang.