explicit function template qualification

Mark Mitchell mmitchell@usa.net
Thu Oct 2 13:28:00 GMT 1997


>>>>> "Mumit" == Mumit Khan <khan@xraylith.wisc.edu> writes:

    Mumit> Jason Merrill <jason@cygnus.com> writes:
    >> I just checked in a patch from Mark to implement explicit
    >> specification of template parameters to function templates.
    >> 
    >> 2) Guiding decls are no longer supported.  So code like

    Mumit> Ouch! This unfortunately breaks lots of my code (easily
    Mumit> fixable however) and a few others floating around the net
    Mumit> (eg., octave breaks miserably).  But that's how the
    Mumit> language works ...

    Mumit> Jason, I tried out your example with operator==<>:

    Mumit>     template <class T> int operator== (const T&, const T&)
    Mumit> { return 0; }

    Mumit>     struct A { A (int) { } friend int operator==<> (const
    Mumit> A&, const A&); };

    Mumit>     main () { A a (1); return a == 1; // << rhs doesn't
    Mumit> match A(int)!  }

    Mumit> And I get the following with egcs-970929 (haven't built the
    Mumit> latest fsf snapshot, so can't comment on that) on
    Mumit> i386-linux-gnulibc1:

    Mumit>     % c++ -c tmpl3.cc tmpl3.cc: In function `int main()':
    Mumit> tmpl3.cc:15: no match for `A & == int'

The language doesn't quite work the way that you expect.  The friend
declaration has no impact, so your code is just like:

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

struct A { A(int); }

main() 
{
  A a;
  a == 1;
}

which has never worked, to my knowledge.

    Mumit> Looks like the user-defined conversions are ignored
    Mumit> (A::A(int)). If I now use the following, everything works
    Mumit> out.

    Mumit>     return a == A(1); // << force rhs match A(int)!

    Mumit> I'm hoping this is just a bug, and not by design. fyi, I've
    Mumit> already reported something similar for 970929 where the
    Mumit> implicit conversions are also botched (eg.,
    Mumit> ``complex<double> + 1'' doesn't work, but ``complex<double>
    Mumit> + 1.0'' works).

    Mumit> Regards, Mumit -- khan@xraylith.wisc.edu
    Mumit> http://www.xraylith.wisc.edu/~khan/

-- 
Mark Mitchell		mmitchell@usa.net
Stanford University	http://www.stanford.edu




More information about the Gcc mailing list