https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70983
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |rejects-valid Last reconfirmed| |2016-5-6 CC| |msebor at gcc dot gnu.org Known to fail| |4.9.3, 5.3.0 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed with 5.3.0 and 4.9.3 in C++ 14 mode. GCC 6.1.0 and 7.0 accept the program as expected. $ cat xxx.c && ~/bin/gcc-5.1.0/bin/g++ -Wall -Wextra -Wpedantic -std=c++14 -xc++ xxx.c template <class T> struct RR { typedef T U; }; template <class T> struct RR<T&> { typedef T U; }; template <class T> typename RR<T>::U&& move (T &&t) { return static_cast<typename RR<T>::U&&>(t); } struct Foo { int& Get () & { return m; } int&& Get () && { return move (m); } auto& GetAuto() & { return m; } auto&& GetAuto() && { return move (m); } int m; }; int main() { Foo foo; int A = foo.Get (); // works int B = foo.GetAuto (); // call is ambiguous } xxx.c: In function ‘int main()’: xxx.c:23:26: error: call of overloaded ‘GetAuto()’ is ambiguous int B = foo.GetAuto (); // call is ambiguous ^ xxx.c:13:12: note: candidate: auto& Foo::GetAuto() auto& GetAuto() & { return m; } ^ xxx.c:14:12: note: candidate: auto&& Foo::GetAuto() auto&& GetAuto() && { return move (m); } ^ xxx.c:22:9: warning: unused variable ‘A’ [-Wunused-variable] int A = foo.Get (); // works ^ xxx.c:23:9: warning: unused variable ‘B’ [-Wunused-variable] int B = foo.GetAuto (); // call is ambiguous ^