This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Conversion templates (Was: ICE980331 *2 with egcs-2.91.47 19980710)


> 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]