[Bug c++/65599] New: [c++14] Failing overload resolution when combining return type deduction and explicit R/L-value methods
anders at sjogren dot info
gcc-bugzilla@gcc.gnu.org
Fri Mar 27 10:55:00 GMT 2015
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
More information about the Gcc-bugs
mailing list