This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Ambiguous conversion with gcc 3.3/3.4
- From: Olivier FOURDAN <olivier dot fourdan at regis-dgac dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Fri, 17 Sep 2004 11:44:52 +0200
- Subject: Ambiguous conversion with gcc 3.3/3.4
- Organization: http://www.transiciel.com
Hi all,
We have the following error occuring with both gcc 3.3 and 3.4 while the
exact same code compiled w/out any warning with gcc 2.95. I understand
that gcc 3.4 is *"much* closer to full conformance to the ISO/ANSI C++
standard", but I'm not sure I fully get the point of the error, and how
to get rid of the ambiguity (in a simple manner ;) ).
./testgcc.cc: In member function `void Y::f()':
./testgcc.cc:65: error: ISO C++ says that these are ambiguous, even
though the worst conversion for the first is better than the worst
conversion for the second:
./testgcc.cc:40: note: candidate 1: bool operator==(const T*, const
_NULL_PTPL_RUNTIME_&) [with T = Y]
./testgcc.cc:65: note: candidate 2: operator==(Y*, Y*) <built-in>
Thanks in advance for your help,
Cheers,
Olivier.
The sample "testgcc.cc" code follows:
//----8<--------8<--------8<---- CUT HERE ----8<--------8<--------8<----//
class _NULL_PTPL_RUNTIME_
{
public :
template<typename T> operator T*() const ;
template<typename T> bool operator ==(const T *right) const ;
template<typename T> bool operator !=(const T *right) const ;
_NULL_PTPL_RUNTIME_() {};
~_NULL_PTPL_RUNTIME_() ;
static const _NULL_PTPL_RUNTIME_ _null_ ;
private :
void operator &() const ;
_NULL_PTPL_RUNTIME_(_NULL_PTPL_RUNTIME_ ©Of) ;
} ;
template<typename T>
_NULL_PTPL_RUNTIME_::operator T*() const
{
return (0);
} ;
template<typename T> bool
_NULL_PTPL_RUNTIME_::operator ==(const T *right) const
{
return (right==(T*)0);
} ;
template<typename T> bool
_NULL_PTPL_RUNTIME_::operator !=(const T *right) const
{
return (right!=(T*)0);
} ;
#undef NULL
#define NULL _NULL_PTPL_RUNTIME_::_null_
template<typename T> bool operator ==(const T *left ,const
_NULL_PTPL_RUNTIME_ &right)
{
return (right.operator ==(left));
};
template<typename T> bool operator !=(const T *left ,const
_NULL_PTPL_RUNTIME_ &right)
{
return (right.operator !=(left));
};
class X
{
public:X() ;
};
class Y:X
{
public:Y();
void f();
} ;
void
Y::f()
{
Y *y = NULL;
if (y == NULL)
{
/* void for now */
}
} ;