19980824, ICE with templated functions

Reid M. Pinchback reidmp@MIT.EDU
Fri Sep 4 08:02:00 GMT 1998


Using the 19980824 snapshot on an alpha-dec-osf4.0d I ran
into the following internal compiler error:

../../egcs-19980824/gcc/expr.c:2468: Internal compiler error in
function emit_move_insn_1

The following code causes it and describes some minor
permutations that cause the ICE to go away.

=========================== 8< cut here 8< ===========================

/*
** private template constructor ICE in converting void
**
** to build:
**   g++ -c bug.cpp -o bug
**
** explanation:
**
**   A templated function that returns a value but has been
**   declared as returning void results in an ICE when used.
**   Non-templated functions don't exhibit this problem.
*/

template <class T> class A {
  template <class T> A(const T& t); // removing this removes the ICE
public:
  T val;
  A(const T& t) : val(t) {}
};

template <class T1, class T2>
inline A<T1> // replacing A<T1> by void doesn't cause
             // the ICE, so the problem probably isn't
             // related to the implicit instantiation of
             // the function template during overload
             // resolution
operator*(const T1& x1, const A<T2>& x2) {
  return T1(x1*x2.val);
}

template <class T1, class T2>
inline void // replace void by A<T2> and the code works
            // and the ICE goes away
operator*(const A<T1>& x1, const A<T2>& x2) {
  return T2(x1.val*x2.val);
}

void f() { return 1; } // this doesn't result in an ICE

main(int argc, char * argv[]) {
  f(); // this doesn't result in an ICE
  A<short> x1((short)1);
  A<int> x2(1);
  A<int> x3=x1*x2;
}

=========================== 8< cut here 8< ===========================
 
 
====================================================
= Reid M. Pinchback                                =
= I/T Delivery, MIT                                =
=                                                  =
= Email:   reidmp@mit.edu                          =
= URL:     http://web.mit.edu/reidmp/www/home.html =
====================================================




More information about the Gcc-bugs mailing list