[Bug c++/60943] [C++14] Return type deduction interferes with ref-qualifiers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60943 --- Comment #4 from Anders Sjögren anders at sjogren dot info --- Thanks for fixing the bug! It seems that the test file https://gcc.gnu.org/viewcvs/gcc/trunk/gcc/testsuite/g%2B%2B.dg/cpp1y/pr60943.C?view=markuppathrev=223502 contains an error. It contains: void Bar (A a) { a.f (); } My guess is that it was meant to call the member function from an R-value object a. However, as an l-value at the site of the call, and both Foo and Bar will select the l-value version. Something like std::move(a).f() or just A{}.f(); should do the trick.
[Bug c++/60943] [C++14] Return type deduction interferes with ref-qualifiers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60943 --- Comment #6 from Anders Sjögren anders at sjogren dot info --- An alternative test case, which also tests that the correct version is selected, could be: #include type_traits using expected_lvalue_res_t = int; using expected_rvalue_res_t = double; struct A { auto f() {return expected_lvalue_res_t{};} auto f() {return expected_rvalue_res_t{};} }; void lvalue_assert() { A a; a.f(); static_assert(std::is_samedecltype(a.f()), expected_lvalue_res_t::value,); } void rvalue_assert() { A{}.f(); static_assert(std::is_samedecltype(A{}.f()), expected_rvalue_res_t::value,); }
[Bug c++/60943] [C++14] Return type deduction interferes with ref-qualifiers
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60943 --- Comment #5 from Anders Sjögren anders at sjogren dot info --- A typo snuck in... However, as an l-value at the site of the call[...] should be However, a is an l-value at the site of the call[...]
[Bug c++/65599] New: [c++14] Failing overload resolution when combining return type deduction and explicit R/L-value methods
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65599 Bug ID: 65599 Summary: [c++14] Failing overload resolution when combining return type deduction and explicit R/L-value methods Product: gcc Version: 4.9.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: anders at sjogren dot info The following code uses return type deduction (auto) and different methods for L-value and R-value objects. It seems when combining the two, gcc 4.9.2 has problems with overload resolution: call of overloaded 'f()' is ambiguous. Is this a bug or just another strange C++ corner case? Clang accepts it as expected. struct T { auto f() { return int{0}; } auto f() { return string{}; } }; void test_it() { //Calling with L-value object. Fails with call of overloaded 'f()' is ambiguous). T t; int s = t.f(); //Calling with R-value object. Fails with call of overloaded 'f()' is ambiguous). string i = T{}.f(); } struct T2 { auto f() - int { return 0; } auto f() - string { return ; } }; void test_it_2() { //Calling with L-value object. Works just fine when the return type is stated! T2 t; int s = t.f(); //Calling with R-value object. Works just fine when the return type is stated! string i = T2{}.f(); } struct T3 { auto f() { return 0; } auto f() - string { return ; } }; void test_it_3() { //Calling with L-value object. Works fine when the non-selected overload has a non-deduced return type(!). T3 t; int s = t.f(); //Calling with R-value object. Doesn't work even though the selected overload has a non-deduced return type. string i = T3{}.f(); } The example can be studied using online compilers here: gcc 4.9.2: http://goo.gl/itZliQ clang 3.5.1: http://goo.gl/yffVa8 The topic on if its a bug or a c++ quirk was posted on http://stackoverflow.com/questions/29298029/c-gcc-bug-when-combining-auto-and-r-value-in-methods , but I also posted it here after that I felt fairly sure it was a bug. A possibly related bug is: Bug 64194 - [C++14] unresolved overloaded function type for function template with auto return