Patch for template conversion operator bug
Mark Mitchell
mmitchell@usa.net
Mon Jan 12 13:22:00 GMT 1998
Jeroen --
Here's a patch for the problem you reported where code like this:
template <class T>
struct A
{
template <class T2>
operator A<T2>() const { return A<T2>(); }
};
main()
{
A<int> a1;
A<long> a2;
A<double> a3;
A<char> a4;
a2 = a1.operator A<long>();
a3 = (A<double>) a1;
a4 = a1;
}
didn't work correctly.
--
Mark Mitchell mmitchell@usa.net
Stanford University http://www.stanford.edu
Index: gcc/cp/call.c
===================================================================
RCS file: /home/mitchell/Repository/egcs/gcc/cp/call.c,v
retrieving revision 1.1.1.6
diff -c -p -r1.1.1.6 call.c
*** call.c 1998/01/01 01:04:26 1.1.1.6
--- call.c 1998/01/12 20:50:25
*************** build_user_type_conversion_1 (totype, ex
*** 4356,4363 ****
if (TREE_CODE (totype) == REFERENCE_TYPE)
convflags |= LOOKUP_NO_TEMP_BIND;
! ics = implicit_conversion
! (totype, TREE_TYPE (TREE_TYPE (fn)), 0, convflags);
if (TREE_CODE (totype) == REFERENCE_TYPE && ics && ICS_BAD_FLAG (ics))
/* ignore the near match. */;
--- 4356,4366 ----
if (TREE_CODE (totype) == REFERENCE_TYPE)
convflags |= LOOKUP_NO_TEMP_BIND;
! if (TREE_CODE (fn) != TEMPLATE_DECL)
! ics = implicit_conversion
! (totype, TREE_TYPE (TREE_TYPE (fn)), 0, convflags);
! else
! ics = implicit_conversion (totype, totype, 0, convflags);
if (TREE_CODE (totype) == REFERENCE_TYPE && ics && ICS_BAD_FLAG (ics))
/* ignore the near match. */;
Index: gcc/testsuite/g++.old-deja/g++.pt/memtemp67.C
===================================================================
RCS file: memtemp67.C
diff -N memtemp67.C
*** /dev/null Mon Dec 31 20:00:00 1979
--- memtemp67.C Mon Jan 12 12:49:14 1998
***************
*** 0 ****
--- 1,19 ----
+ template <class T>
+ struct A
+ {
+ template <class T2>
+ operator A<T2>() const { return A<T2>(); }
+ };
+
+ main()
+ {
+ A<int> a1;
+ A<long> a2;
+ A<double> a3;
+ A<char> a4;
+
+ a2 = a1.operator A<long>();
+ a3 = (A<double>) a1;
+ a4 = a1;
+ }
+
More information about the Gcc-bugs
mailing list