home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / gnu / g / bug / 2352 < prev    next >
Encoding:
Text File  |  1993-01-28  |  3.5 KB  |  143 lines

  1. Path: sparky!uunet!stanford.edu!agate!ames!saimiri.primate.wisc.edu!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!hoffman.rstnu.bcm.tmc.edu!wje
  2. From: wje@hoffman.rstnu.bcm.tmc.edu (Bill Eaton)
  3. Newsgroups: gnu.g++.bug
  4. Subject: multiple inheritance abort
  5. Date: 26 Jan 1993 22:18:21 -0500
  6. Organization: GNUs Not Usenet
  7. Lines: 130
  8. Sender: daemon@cis.ohio-state.edu
  9. Approved: bug-g++@prep.ai.mit.edu
  10. Distribution: gnu
  11. Message-ID: <199301262015.AA29998@HOFFMAN.RSTNU.BCM.TMC.EDU>
  12.  
  13. gcc-2.3.3:  C++ bug, multiple inheritance and virtual functions can
  14. lead to bad method calls.  It was observed on mips-sgi-irix4, but should
  15. affect all platforms.
  16.  
  17.      Some combinations of multiple inheritance and virtual functions can
  18. give rise to a bad virtual function table which results in unexpected
  19. method calls.  A slight modification of the problem case gives an
  20. "Internal compiler error" abort.  The original problem turned up in
  21. InterViews 3.1 in the "doc" program involving class ItemView.
  22.  
  23.      The source file below will give the compiler abort.  Uncommenting the
  24. indicated lines and recompiling will demonstrate the bad method calls.
  25. The abort happens in modify_vtable_entry () from dereferencing a NULL
  26. old_entry_in_list.
  27.  
  28. Call chain:  modify_vtable_entry, modify_vtable_entries,
  29. add_virtual_function, finish_struct, yyparse, compile_file, main.
  30.  
  31. C++ source file inherit.cc
  32. --------------------------------------------------
  33. extern "C" {extern void printf (char*);}
  34.  
  35. typedef int boolean;
  36. typedef int Requisition;
  37.  
  38. class Resource {
  39. public:
  40.     virtual void ref() const;
  41. };
  42.  
  43. void Resource::ref () const { printf ("Resource::ref\n"); }
  44.  
  45.  
  46.  
  47. typedef int Event;
  48.  
  49. class Handler : public Resource {
  50. public:
  51.     virtual ~Handler ();
  52.     virtual boolean event (Event&);
  53. };
  54.  
  55. Handler::~Handler () { printf ("Handler destructor\n"); }
  56. Handler::event (Event& e) { printf ("Handler::event\n"); return 1; }
  57.  
  58.  
  59.  
  60. class Glyph : public Resource {
  61. public:
  62.     virtual void request(Requisition&) const;
  63. };
  64.  
  65. void Glyph::request (Requisition& r) const
  66. {
  67.   printf ("Glyph::request\n");
  68. }
  69.  
  70.  
  71.  
  72. class MonoGlyph : public Glyph {
  73. public:
  74. // Uncommenting the line below allows this to compile, but gives a bad
  75. // vtable for ItemView.
  76.  
  77. //  virtual ~MonoGlyph () { printf ("MonoGlyph destructor\n"); }
  78.     virtual void request(Requisition&) const;
  79.  
  80. protected:
  81.     MonoGlyph(Glyph* = 0);
  82. };
  83.  
  84. MonoGlyph::MonoGlyph (Glyph* g) { ; }
  85.  
  86.  
  87.  
  88. void MonoGlyph::request (Requisition& r) const
  89. {
  90.   printf ("MonoGlyph::request\n");
  91. }
  92.  
  93.  
  94.  
  95. class ItemView : public MonoGlyph, public Handler {
  96. public:
  97.     ItemView ();
  98.  
  99.     virtual boolean event (Event&);
  100. };  // The "Internal compiler error" is seen here.
  101.  
  102. ItemView::ItemView () { ; }
  103. ItemView::event (Event& e) { printf ("ItemView::event\n"); return 1; }
  104.  
  105.  
  106.  
  107. void foo (ItemView* v, Requisition& r)
  108. {
  109.   v->request (r);
  110. }
  111.  
  112. int main (void)
  113. {
  114.   ItemView  i;
  115.   Requisition r = 42;
  116.  
  117.   foo (&i, r);
  118.   return 0;
  119. }
  120. --------------------------------------------------
  121.  
  122. % gcc -o inherit inherit.cc
  123. inherit.cc:68: Internal compiler error.
  124. inherit.cc:68: Please report this to `bug-g++@prep.ai.mit.edu'.
  125.  
  126. Uncommenting the ~MonoGlyph line and recompiling gives this:
  127.  
  128. % gcc -o inherit inherit.cc
  129. % inherit
  130. Handler destructor
  131. MonoGlyph destructor
  132. Handler destructor
  133. MonoGlyph destructor
  134.  
  135. It should call MonoGlyph::request ().
  136.  
  137. Sorry, no patch included.
  138. William J. Eaton, keeper of the Temple of Apollo Workstations
  139. Email wje@hoffman.rstnu.bcm.tmc.edu   | If it looks like I know what I'm
  140. Phone (713) 798-5161                  | doing, it's an optical illusion!
  141. Dhvg ernqvat znvy be arjf naq trg onpx gb jbex!
  142.  
  143.