[gnu.g++.bug] g++-1.36.4 segv

tiemann@arkesden.eng.sun.com (Michael Tiemann) (02/05/90)

   Posted-Date: Fri, 2 Feb 90 22:17:50 CST
   Date: Fri, 2 Feb 90 22:17:50 CST
   From: vaughan%cadillac.cad.mcc.com@mcc.com (Paul Vaughan)


   The following source cause g++-1.36.4  to crash


   class Foo;
   class Entity {
   private:
     Entity* owner=0 ;
   };

   class MessagePort : public virtual Entity {
   public:
     MessagePort(Foo*);
   private:
     Foo& owner;
   };

   MessagePort::MessagePort(Foo* o)
	: owner(*o)
   {
   } //line 18

   --------------------------
   g++-1.36.4: Program cc1plus got fatal signal 11.
   [1.300]puma) g++-1.36.4 -v cpp.cc
   g++ version 1.36.4 (based on GCC 1.36.93)
    /usr/local/gnu/1.36.4/lib/gcc-cpp -+ -v -undef -D__GNUC__ -D__GNUG__ -D__cplusplus -Dmc68000 -Dsun -Dunix -D__mc68000__ -D__sun__ -D__unix__ -D__HAVE_68881__ -Dmc68020 cpp.cc /usr/tmp/cca03352.cpp
   GNU CPP version 1.36.92
    /usr/local/gnu/1.36.4/lib/gcc-cc1plus /usr/tmp/cca03352.cpp -quiet -dumpbase cpp.cc -version -o /usr/tmp/cca03352.s
   GNU C++ version 1.36.4 (based on GCC 1.36.93) (68k, MIT syntax) compiled by GNU C version 1.36.92.
   default target switches: -m68020 -mc68020 -m68881 -mbitfield
   cpp.cc: In method MessagePort::MessagePort (class Foo *):
   cpp.cc:18: Segmentation violation
   g++-1.36.4: Program cc1plus got fatal signal 11.



   But, the following code compiles cleanly


   class Foo;
   class Entity {
   private:
     Entity* owner=0 ;
   };

   class MessagePort : public Entity {
   public:
     MessagePort(Foo*);
   private:
     Foo& owner;
   };

   MessagePort::MessagePort(Foo* o)
	: owner(*o)
   {
   } //line 18

   The difference is that Entity is not a virtual base class here.  I'm
   not sure of the rule here.  Is this inadmissable code or not?  Anyway,
   it isn't the code I want now that I see the problem.

Here's the patch:

    arkesden% diff -c2 cplus-init.c~ cplus-init.c
    *** cplus-init.c~	Tue Jan 30 21:43:31 1990
    --- cplus-init.c	Sun Feb  4 20:41:11 1990
    ***************
    *** 380,384 ****
	    tree field = (TREE_CODE (name) == COMPONENT_REF
			? TREE_OPERAND (name, 1) : IDENTIFIER_CLASS_VALUE (name));
    !       tree type = TREE_TYPE (field);

	    if (TREE_STATIC (field))
    --- 380,394 ----
	    tree field = (TREE_CODE (name) == COMPONENT_REF
			? TREE_OPERAND (name, 1) : IDENTIFIER_CLASS_VALUE (name));
    !       tree type;
    !       
    !       /* If one member shadows another, get the outermost one.  */
    !       if (TREE_CODE (field) == TREE_LIST)
    ! 	{
    ! 	  field = TREE_VALUE (field);
    ! 	  if (DECL_CONTEXT (field) != current_class_type)
    ! 	    error ("field `%s' not in immediate context");
    ! 	}
    ! 
    !       type = TREE_TYPE (field);

	    if (TREE_STATIC (field))
    arkesden% 

Michael