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]

inline template not expanded.



 An inline template function is not expanded with version egcs-2.90.12. It
works with egcs-2.90.11. Remove a friend declaration of the function
in a template class fix it.

verdi 116- /usr/tmp/test/bin/c++ -V egcs-2.90.10 temp.cc -g
verdi 117- /usr/tmp/test/bin/c++ -V egcs-2.90.12 temp.cc -g
Undefined                       first referenced
 symbol                             in file
operator<<(str &, w<float> const &) /var/tmp/cca0000T1.o
operator<<(str &, w<int> const &)   /var/tmp/cca0000T1.o
ld: fatal: Symbol referencing errors. No output written to a.out
collect2: ld returned 1 exit status

thanks

Pierre TURLAIS

----------------   temp.cc ------------------

#include <stdio.h>

class str;

template<class T>
class w {
public:
    w() { i = 0; }
    void set(T a) { i = a;}
private:
    // Problem with this friend declaration. Removing it fix the problem
    friend str& operator<<(str&, const w<T>&);

    T value () const { return i;}
    T i;
};

class str {
public:
    str() { file = stdout; }
    void put(short i) { fprintf(file, "short %d\n", i); }
    void put(int i) { fprintf(file, "int %d\n", i); }
    void put(float i) { fprintf(file, "float %f\n", i); }
    void put(double i) { fprintf(file, "double %f\n", i); }
private:
    FILE *file;
};

template<class T>
inline str&
operator <<(str& o, const w<T>& ww) {
    o.put(ww.value());
    return o;
}

int main(int argc, char *argv[])
{
    str so;
    w<int> wi;
    w<float> wf;

    wi.set(23);
    wf.set(12.45);

    so << wi << wf;
}


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