This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/49637] New: template function overload incorrectly ambiguous
- From: "timothyjgiese at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 5 Jul 2011 02:03:45 +0000
- Subject: [Bug c++/49637] New: template function overload incorrectly ambiguous
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49637
Summary: template function overload incorrectly ambiguous
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: timothyjgiese@gmail.com
Created attachment 24685
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=24685
gcc -v -save-temps main.cpp [[stderr]]
The following code works fine with gcc 4.4.3 20100127 (and I'm pretty sure it
worked with 4.6.0 before I updated gcc-c++ yesterday); so maybe this is a
regression from a relatively recent change.
Here's the minimal test case:
struct S { typedef int iterator; };
template <typename T, typename U> void F( typename T::iterator, U ) {}
template <typename T> void F( typename T::iterator, int ) {}
int main()
{
S::iterator i(42);
F<S>(i,1); // FAILS=4.6.0 20110530 ; OK=4.4.3 20100127
return 0;
}
g++ without any other options produces the following (incorrect) error:
main.cpp: In function âint main()â:
main.cpp:7:11: error: call of overloaded âF(S::iterator&, int)â is ambiguous
main.cpp:7:11: note: candidates are:
main.cpp:2:40: note: void F(typename T::iterator, U) [with T = S, U = int,
typename T::iterator = int]
main.cpp:3:28: note: void F(typename T::iterator, int) [with T = S, typename
T::iterator = int]
Earlier version of g++ did not produce this error.
Note that if I change the definition of F to void F(T,U) and void F(T,int) and
pass in S::iterator as the template argument, then it compiles without error.
So, it's somehow having a problem with the typename with deduction.
I'd be appreciative if someone simply confirmed if this is a bug or not.
I have a lot of code that fails now that didn't fail a few days ago, and I'm
now wondering if I need to change my code or change back to an older compiler
until this gets resolved.