This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/24011] New: ambiguous overload reported for no obvious reason
- From: "andre_orwell at yahoo dot com dot au" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 22 Sep 2005 15:08:53 -0000
- Subject: [Bug c++/24011] New: ambiguous overload reported for no obvious reason
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
// Barebones code to reproduce the problem:
// Interface
namespace NS
{
template<typename T> class X {};
template<typename T> X<T> operator*(const X<T> &a, const X<T> &b);
}
// Implementation
template<typename T>
NS::X<T>operator*(const NS::X<T> &a,const NS::X<T> &b)
{
return NS::X<T>();
}
// Application
int main(int argc, char *argv[])
{
NS::X<int> tmp = NS::X<int>() * NS::X<int>();
}
What I get:
-bash-3.00$ uname -a
Linux elisha.research.canon.com.au 2.6.12-1.1447_FC4smp #1 SMP Fri Aug 26
20:57:13 EDT 2005 i686 i686 i386 GNU/Linux
-bash-3.00$ gcc --version
gcc (GCC) 4.0.1 20050727 (Red Hat 4.0.1-5)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-bash-3.00$ make strange
g++ -g strange.cpp -o strange
strange.cpp: In function 'int main(int, char**)':
strange.cpp:19: error: ambiguous overload for 'operator*' in 'NS::X<int>() *
NS::X<int>()'
strange.cpp:11: note: candidates are: NS::X<T> operator*(const NS::X<T>&,
constNS::X<T>&) [with T = int]
strange.cpp:6: note: NS::X<T> NS::operator*(const NS::X<T>&,
const NS::X<T>&) [with T = int]
make: *** [strange] Error 1
If I place the implementation within the scope of the namespace geometry{...}
then it seems to compile fine. However the above does not appear to cause
problems using MSVC. Problem exists with gcc 3.3.2 and 3.3.4. Is this code
incorrect???
Thanks
--
Summary: ambiguous overload reported for no obvious reason
Product: gcc
Version: 4.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andre_orwell at yahoo dot com dot au
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: redhat.x86.linux
GCC host triplet: redhat.x86.linux
GCC target triplet: redhat.x86.linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24011