http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57254
Bug ID: 57254
Summary: Overload resolution failure when member function
tempate is defined out-of-line
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: lucdanton at free dot fr
Using 4.9.0 20130509 (experimental) [trunk revision 198734] and -std=c++11 the
following is rejected:
//---
struct foo {
template<typename T>
void bar(T) &;
template<typename T>
void bar(T) &&;
};
template<typename T>
void foo::bar(T) & {}
template<typename T>
void foo::bar(T) && {}
int main()
{
foo f;
// error: call of overloaded 'bar(int)' is ambiguous
f.bar(0);
}
//---
Output is:
main.cpp: In function 'int main()':
main.cpp:19:12: error: call of overloaded 'bar(int)' is ambiguous
f.bar(0);
^
main.cpp:19:12: note: candidates are:
main.cpp:10:6: note: void foo::bar(T) [with T = int]
void foo::bar(T) & {}
^
main.cpp:13:6: note: void foo::bar(T) [with T = int]
void foo::bar(T) && {}
^
If on the other hand the members are defined inline, the code is accepted.
Similarly if bar is made a set of non-template functions and e.g. T is an alias
for int.