template unification bug?

Mark Mitchell mmitchell@usa.net
Wed Feb 11 15:33:00 GMT 1998


>>>>> "Stefan" == Stefan Meixner <stefan@emskopp.a.shuttle.de (none)> writes:

    Stefan> Hi,

    Stefan> right now I do not see why the following code does not
    Stefan> compile!  Please correct me if I am wrong!

You are wrong.  The compiler doesn't use the fact that foo(5) is being
assigned into an A<double> when doing type unification, nor should
it.  You can write foo<double>(5) to do this yourself.

    >> g++ -v
    Stefan> Reading specs from
    Stefan> /usr/lib/gcc-lib/i486-pc-linux-gnulibc1/egcs-2.91.07/specs
    Stefan> gcc version egcs-2.91.07 980205 (gcc-2.8.0 release)

    >> g++ -o unibug unibug.cc
    Stefan> unibug.cc: In function `int main()': unibug.cc:25:
    Stefan> incomplete type unification unibug.cc:25: no matching
    Stefan> function for call to `foo (int)'

    Stefan> ====================================================== //
    Stefan> unibug.cc

    Stefan> template<class T> class A;

    Stefan> template<class T> A<T> foo(int a);

    Stefan> template<class T> class A { public: A() { } A(int a) { }
    Stefan> };

    Stefan> template<class T> A<T> foo(int a) { return A<T>(a); }

    Stefan> int main() {

    Stefan>    A<double> c;

    Stefan>    c = foo(5);


    Stefan>    return 0; }

    Stefan> =======================================================

    Stefan> Stefan

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




More information about the Gcc-bugs mailing list