🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #842

Re: initializer for virtual base class.

#842
From: Mike Stump
Date: Sat, 29 Aug 1992 17:49
64 lines
2760 bytes
This problem should not exist in the next release of gcc.

Here is a patch in the mean time:

*** cp-init.c.~1~	Tue Aug 25 16:38:30 1992
--- cp-init.c	Sat Aug 29 10:33:51 1992
*************** emit_base_init (t, immediately)
*** 257,263 ****
  	      /* Virtual base classes are special cases.  Their initializers
  		 are recorded with this constructor, and they are used when
  		 this constructor is the top-level constructor called.  */
! 	      if (! TREE_VIA_VIRTUAL (binfo) || pedantic)
  		{
  		  /* Otherwise, if it is not an immediate base class, complain.  */
  		  for (i = n_baseclasses-1; i >= 0; i--)
--- 257,263 ----
  	      /* Virtual base classes are special cases.  Their initializers
  		 are recorded with this constructor, and they are used when
  		 this constructor is the top-level constructor called.  */
! 	      if (! TREE_VIA_VIRTUAL (binfo))
  		{
  		  /* Otherwise, if it is not an immediate base class, complain.  */
  		  for (i = n_baseclasses-1; i >= 0; i--)


> Date: Sun, 23 Aug 92 15:38:46 -0500
> From: solomon@cs.wisc.edu (Marvin Solomon)
> Message-Id: <9208232038.AA22890@gjetost.cs.wisc.edu>
> To: bug-g++@prep.ai.mit.edu

> When -pedantic is specified, g++ 2.2.2 won't allow an initializer for
> a virtual base class, but it also complains that the initializer is missing.

> 	extern "C" void printf(...);

> 	struct A {
> 		A(int i) { printf("A::A(%d)\n", i); }
> 	};

> 	struct B : virtual A {
> 		B(int i) : A(i+1) { printf("B::B(%d)\n", i); }
> 	};

> 	struct C : B {
> 		C(int i) : B(i+1), A(i+2) { printf("C::C(%d)\n", i); } // line 12
> 	};

> 	main() {
> 		C(1);
> 	}
> When compiled with 'g++ -pedantic', the messages are:
> 	foo.c: In method `C::C (int)':
> 	foo.c:12: type `A' is not an immediate base class of type `C'
> 	foo.c:12: virtual baseclass `A' does not have default initializer
> 	foo.c:12: type `A' is not an immediate base class of type `C'
> When compiled without -pedantic (even if -Wall is specified) there are
> no errors or warnings, and the correct output is produced:
> 	A::A(3)
> 	B::B(2)
> 	C::C(1)
> If line 12 is changed to
> 		C(int i) : B(i+1) { printf("C::C(%d)\n", i); } // line 12
> there is only one message (with or without -pedantic):
> 	foo.c:12: virtual baseclass `A' does not have default initializer
Technical Details
Message-ID: <9208291749.AA01477@cygnus.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrs

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!usc!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!cygnus.com!mrs
From: mrs@cygnus.com (Mike Stump)
Subject: Re:  initializer for virtual base class.
Message-ID: <9208291749.AA01477@cygnus.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Sat, 29 Aug 1992 17:49:13 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 65