C++ generates bad assembly code

David Mazieres dm@reeducation-labor.lcs.mit.edu
Tue Jun 16 17:39:00 GMT 1998


With recent versions of egcs:
  gcc version egcs-2.91.40 19980610 (gcc2 ss-980502 experimental)
  gcc version egcs-2.91.41 19980616 (gcc2 ss-980502 experimental)

The following program compiles to incorrect assembly code if you do
not optimize.  (It works with gcc2 and egcs 1.03.)

On an OpenBSD i386 machine, I get the following:

% c++ -c egcs-bug.C
/var/tmp/ccCSF766.s: Assembler messages:
/var/tmp/ccCSF766.s:28: Fatal error:Symbol ___t11ihash_entry1Z7element already defined.

% c++ -c egcs-bug.C |& c++filt
/var/tmp/ccER3108.s: Assembler messages:
/var/tmp/ccER3108.s:28: Fatal error:Symbol ihash_entry<element>::ihash_entry(void) already defined.

Thanks,
David

===

template<class T>
class ihash_entry {
};

template<class T, ihash_entry<T> T::*field>
struct ihash_core {
  ihash_core () {}
};

template<class T, ihash_entry<T> T::*field>
struct ihash : public ihash_core<T, field>
{
  ihash () {}
};

struct element {
  ihash_entry<element> hlink;
};

ihash<element, &element::hlink> etab;



More information about the Gcc-bugs mailing list