https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64562
Bug ID: 64562 Summary: Member functions with r-value reference for *this and deduced return type incorrectly rejected as ambiguous Product: gcc Version: 4.9.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: sneves at dei dot uc.pt Consider the following program: #include <iostream> #define RETURN_TYPE auto namespace { struct S { RETURN_TYPE operator--() && { return 1; } RETURN_TYPE operator--() const && { return 2; } RETURN_TYPE operator--() & { return 3; } RETURN_TYPE operator--() const & { return 4; } }; const S callme() { return {}; } auto f1() { return --S(); } auto f2() { return --callme(); } auto f3() { S s; return --s; } auto f4() { const S s {}; return --s; } } int main() { std::cout << f1() << " "; std::cout << f2() << " "; std::cout << f3() << " "; std::cout << f4() << std::endl; } The expected output would be "1 2 3 4". When RETURN_TYPE is defined to be "int", this is the result obtained. GCC (versions ranging from 4.8.2 to the latest build), however, rejects this code when RETURN_TYPE is defined to be "auto" or "decltype(auto)".