This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Bug in implicit conversion (gcc 3.4.1)?
- From: "Giovanni Bajo" <rasky at develer dot com>
- To: "Boris von Loesch" <vonloesch at gmail dot com>
- Cc: <gcc at gcc dot gnu dot org>
- Date: Fri, 27 Aug 2004 19:06:23 +0200
- Subject: Re: Bug in implicit conversion (gcc 3.4.1)?
- References: <41a2e2dc040826070335183570@mail.gmail.com>
Boris von Loesch wrote:
> template <class T> class BasisF;
>
> template <class T> inline bool operator<=(const BasisF<T> &a, const
> BasisF<T> &b){return a.x <= b.x;}
>
> template<class T> class BasisF{
>
> public:
> T x;
> BasisF(const T &_x = T()): x(_x){}
> BasisF(const BasisF &_b): x(_b.x){}
> ~BasisF(){}
> BasisF& operator= (const T &_x){
> x = _x;
> return *this;
> }
> friend bool operator<=<>(const BasisF &a, const BasisF &b);
> };
>
> #define min(a,b) ((a) <= (b) ? (a) : (b))
>
> int main(){
> BasisF<double> t(1);
> if (min(t,2.0)<=0) return 1;
> return 0;
> }
> If I move the operator implementation into the class, it works:
> template<class T> class BasisF{
> ...
> friend bool operator<=(const...,...){ return a.x<=b.x; }
> };
>
> Is this a bug?
No, it's not a bug, GCC behaves correctly now. Your template function cannot
be matched because the deduction for the template parameter fails (and this
is before any standard conversion can be applied). Defining the inline
friend function works because it is a regular function which is pushed into
the global scope, so there is no deduction to be performed, and the compiler
will find the default conversion which makes the call possible.
The details are hairy, so I suggest you to ask somewhere else (such as the
newsgroup comp.lang.c++.moderated) for more information
Giovanni Bajo