public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/24011] New: ambiguous overload reported for no obvious reason
@ 2005-09-22 15:10 andre_orwell at yahoo dot com dot au
2005-09-22 15:18 ` [Bug c++/24011] " pinskia at gcc dot gnu dot org
2005-09-23 13:35 ` andre_orwell at yahoo dot com dot au
0 siblings, 2 replies; 3+ messages in thread
From: andre_orwell at yahoo dot com dot au @ 2005-09-22 15:10 UTC (permalink / raw)
To: gcc-bugs
// 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
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/24011] ambiguous overload reported for no obvious reason
2005-09-22 15:10 [Bug c++/24011] New: ambiguous overload reported for no obvious reason andre_orwell at yahoo dot com dot au
@ 2005-09-22 15:18 ` pinskia at gcc dot gnu dot org
2005-09-23 13:35 ` andre_orwell at yahoo dot com dot au
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-22 15:18 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-09-22 15:17 -------
the error message about ambiguous overload is correct as there are two functions there.
operator* in the global namespace and operator* in the NS namespace.
You most likely wanted to implement operator* in the NS namespace and not a new one in the global
namespace.
The following code does what you wanted to do:
// 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>NS::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>();
}
Notice how I wrote the Implementation.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24011
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c++/24011] ambiguous overload reported for no obvious reason
2005-09-22 15:10 [Bug c++/24011] New: ambiguous overload reported for no obvious reason andre_orwell at yahoo dot com dot au
2005-09-22 15:18 ` [Bug c++/24011] " pinskia at gcc dot gnu dot org
@ 2005-09-23 13:35 ` andre_orwell at yahoo dot com dot au
1 sibling, 0 replies; 3+ messages in thread
From: andre_orwell at yahoo dot com dot au @ 2005-09-23 13:35 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From andre_orwell at yahoo dot com dot au 2005-09-23 13:34 -------
Subject: Re: ambiguous overload reported for no obvious reason
Thanks - obvious when its pointed out. Sorry for the bother.
On Friday 23 September 2005 01:17, pinskia at gcc dot gnu dot org wrote:
> The following code does what you wanted to do:
...
> Notice how I wrote the Implementation.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24011
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-09-23 13:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-22 15:10 [Bug c++/24011] New: ambiguous overload reported for no obvious reason andre_orwell at yahoo dot com dot au
2005-09-22 15:18 ` [Bug c++/24011] " pinskia at gcc dot gnu dot org
2005-09-23 13:35 ` andre_orwell at yahoo dot com dot au
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).