This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Conversion templates (Was: ICE980331 *2 with egcs-2.91.47 19980710)
- To: Franz dot Sirl-kernel at lauterbach dot com
- Subject: Conversion templates (Was: ICE980331 *2 with egcs-2.91.47 19980710)
- From: Martin von Loewis <martin at mira dot isdn dot cs dot tu-berlin dot de>
- Date: Tue, 14 Jul 1998 10:13:31 +0200
- CC: egcs-bugs at cygnus dot com
- References: <98071221082700.14209@ns1102.munich.netsurf.de>
> Please comment on the conversion warnings produced by htmlview.ii,
> since I already asked twice here and nobody seems to know whether
> this warning is correct or not (or what qt is doing wrong here).
For discussion purposes, I've reduced this to a smaller example:
template<class T>
struct Base{
operator T()const;
};
struct Derived:Base<int>
{
operator int()const;
};
void f()
{
Derived x;
int i=x;
}
g++ complains:
x.ii:14: warning: choosing `Derived::operator int() const' over
`Base<int>::operator int<int>() const' ...
AFAICT, g++ does the right thing, by accident, and the warning is not
necessary.
I believe Derived::operator int()const hides Base::operator
int<int>()const ([class.conv]/5, which does not mention const-ness of
this, for some reason). As a result, the Base operator is not a
candidate ([over.match.conv]/1).
So g++ selects the right candidate, but considers non-candidates, and
complains about that.
I'm not sure what the right fix is (does the standard really mean that
Derived::operator foo() could hide Base::operator foo()volatile?), and
I don't know how to fix that - I'd rather leave implicit conversion to
other people (hi Jason).
Hope this helps,
Martin