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]

Template instantiation dies on cast


The following test case generates the following output. The source
program is bit nonsensical; it's what happens when you boil down
complex hunk of code you didn't write (some Rogue Wave library
code...) into a small test case. 

Please contact me if you can't reproduce the bug, or if you have a
fix. :-)

I'm running egcs 1.02 as shipped with RedHat 5.1. This compiles
cleanly on g++ 2.7.2.1 (and on the Sunpro compiler on a SPARC).

-- Jerry Callen
   jcallen@world.std.com

---------------------- source code ---------------------

// -*-Mode: C++-*-

template <class T> class  TemplateClass1 
{
public:
  // compiler-supplied ctor/copy/assign/dtor OK
  void apply(void (*applyFun)(T&)) 
    {(*applyFun)(item1_);}

private:
  T item1_;
};

template <class T> class TemplateClass2
{
public:
  // compiler-supplied ctor/copy/assign/dtor OK
  void apply(void (*applyFun)(const T&))
    {
      void (*nonConstApplyFun) (T&);
      /*
	A compiler error occurs in the following 
	statement, which is casting away const on
	the template arg of the function. (Yes, this
	nonsensical, but it's the result of boiling down
	a much larger test to this small test.)
      */

      nonConstApplyFun =
	(void (*)(T&))applyFun;

      item2_.apply(nonConstApplyFun);
    }

private:
  TemplateClass1<T> item2_;
};

template class TemplateClass2<int>;

------------------------------ compiler listing ----------------

# g++ -v   -c test2.C -o test2.o
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.90.27/specs
gcc version egcs-2.90.27 980315 (egcs-1.0.2 release)
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.90.27/cpp -lang-c++ -v -undef -D__GNUC__=2 -D__GNUG__=2 -D__cplusplus -D__GNUC_MINOR__=90 -Di386 -D__ELF__ -Dunix -Dlinux -D__i386__ -D__ELF__ -D__unix__ -D__linux__ -D__i386 -D__unix -D__linux -Asystem(posix) -D__EXCEPTIONS -Di386 -Asystem(unix) -Acpu(i386) -Amachine(i386) -D__i386__ -Asystem(unix) -Acpu(i386) -Amachine(i386) test2.C /tmp/cca00862.ii
GNU CPP version egcs-2.90.27 980315 (egcs-1.0.2 release) (i386 Linux/ELF)
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++
 /usr/i386-redhat-linux/include
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.90.27/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/egcs-2.90.27/cc1plus /tmp/cca00862.ii -quiet -dumpbase test2.cc -version -o /tmp/cca00862.s
GNU C++ version egcs-2.90.27 980315 (egcs-1.0.2 release) (i386-redhat-linux) compiled by GNU C version egcs-2.90.27 980315 (egcs-1.0.2 release).
test2.C: In method `void TemplateClass2<int>::apply(void (*)(const int &))':
test2.C:30: Internal compiler error.
test2.C:30: Please submit a full bug report to `egcs-bugs@cygnus.com'.
# 


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