This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
member-templates : type conversion doesnt work
- To: egcs-bugs at cygnus dot com
- Subject: member-templates : type conversion doesnt work
- From: jeroen dobbelaere xe44 7682 <dobbelaj at access dot bel dot alcatel dot be>
- Date: Tue, 6 Jan 1998 17:10:31 +0100
- cc: dobbelaj at btmpm3 dot access dot bel dot alcatel dot be
I think I have found a bug :
when working with member templates, I need to have an automatic type
conversion (defined as a member template).
egcs-1.0 doesn't automagically instantiate the needed convertor.
Example :
-- test.cpp --
#include <iostream.h>
template <class T>
class A
{
public:
A() {}
~A() {}
template <class T2>
operator A<T2>() const { cout << "Converted" << endl; return A<T2>(); }
operator int() const { cout << "Conversion to int" << endl; return 5; }
};
main()
{
A<int> a1;
A<long> a2;
int i;
i=a1;
i=a2;
a2=a1.operator A<long>(); // works
a2=a1; // doesnt work, but should have the same effect
}
--
g++ -Wall -Weffc++ test2.cpp
/ap/GNUpro/egcs-1.0/include/g++/iostream.h: In method `class _IO_istream_withassign & _IO_istream_withassign::operator =(class _IO_istream_withassign &)':
In file included from test2.cpp:1:
/ap/GNUpro/egcs-1.0/include/g++/iostream.h:237: warning: `operator=' should return a reference to `*this'
/ap/GNUpro/egcs-1.0/include/g++/iostream.h: In method `class _IO_ostream_withassign & _IO_ostream_withassign::operator =(class _IO_ostream_withassign &)':
/ap/GNUpro/egcs-1.0/include/g++/iostream.h:244: warning: `operator=' should return a reference to `*this'
test2.cpp: In function `int main()':
test2.cpp:27: no match for `A<long int> & = A<int> &'
test2.cpp:19: candidates are: A<long int>::operator =(const A<long int> &)
-> egcs should try the A<int>::operator A<long>()
Greetings,
Jeroen Dobbelaere
BTW, thanx for providing such a wonderfull product !