Topic: Operator lookup


Author: Roman Lechtchinsky <wolfro@cs.tu-berlin.de>
Date: 1996/10/16
Raw View
Hi,

recently I've discovered that my compiler (BC5) behaves in a rather strange
way when dealing with operator templates. Consider the following code:

class A {
public:
 bool operator==( const A& ) const;
};

template<class T>
bool operator==( const T&, const T& );

int main()
{
 A a1, a2;
 a1==a2;
}

The compiler uses the template for the comparison in main. This is certainly
not what I've expected. I've checked the DWP but couldn't find any wording
that would address this case. What should be the correct behaviour? BTW, if I
change the template declaration to

bool operator==( const A&, const A& );

I get an "ambigous call" error message.

Bye

Roman


[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]





Author: clamage@taumet.eng.sun.com (Steve Clamage)
Date: 1996/10/16
Raw View
Roman Lechtchinsky wrote:
>
> recently I've discovered that my compiler (BC5) behaves in a rather strange
> way when dealing with operator templates. Consider the following code:
>
 [deleted]
>
> The compiler uses the template for the comparison in main. This is certainly
> not what I've expected. I've checked the DWP but couldn't find any wording
> that would address this case. What should be the correct behaviour?

I think your compiler is broken.  According to the 1/96 working paper:

  13.3.3  Best Viable Function                         [over.match.best]

1 ...Given these definitions, a viable function F1
  is defined to be a better function than another viable function F2  if
  for  all arguments i, ICSi(F1) is not a worse conversion sequence than
  ICSi(F2), and then

 ...

  --F1  is a non-template function and F2 is a template function, or, if
    not that,

In other words, the member function should have been the best match,
because it is a non-template function.

--
Michael P Lindner
mpl@cmprime.att.com



[ comp.std.c++ is moderated.  To submit articles: try just posting with      ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu         ]
[ FAQ:      http://reality.sgi.com/employees/austern_mti/std-c++/faq.html    ]
[ Policy:   http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu                             ]