🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

`new T(I)' silently ignores I if T has no constructor

#420
From: Paul Eggert
Date: Thu, 14 Sep 1989 01:29
45 lines
1438 bytes
G++ 1.35 ignores initializers of `new' if no constructor is defined for the
corresponding class.  An error message should be issued instead.
Here is an example.

	struct complex { int re, im; };

	main()
	{
		complex *zp1 = new complex(5,10);
		return zp1->re;
	}

`main()' yields garbage (that happens to be zero) when compiled by G++ 1.35
(Sun-3/50 + SunOS 4.0.3).  Here is the Sun-3 assembly language output:

	#NO_APP
	gcc_compiled.:
	.text
		.even
	.globl _main
	_main:
		link a6,#-4
		pea 8:w
		jbsr ___builtin_new
		movel d0,a6@(-4)
		movel a6@(-4),a0
		movel a0@,d1
		movel d1,d0
		jra L1
	L1:
		unlk a6
		rts

The 5 and 10 were silently ignored.  Instead, the error message "constructor
syntax used, but no constructor declared for type `complex'" should have been
issued.  Such a message is correctly issued for the following program, which
makes a similar error without `new'.

	struct complex { int re, im; };

	main()
	{
		complex zp1(5,10);
		return zp1.re;
	}
Technical Details
Message-ID: <8909140129.AA04866@burns.twinsun.com>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!burns.twinsun.com!eggert

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!burns.twinsun.com!eggert
From: eggert@burns.twinsun.com (Paul Eggert)
Newsgroups: gnu.g++.bug
Subject: `new T(I)' silently ignores I if T has no constructor
Message-ID: <8909140129.AA04866@burns.twinsun.com>
Date: 14 Sep 89 01:29:43 GMT
Sender: daemon@tut.cis.ohio-state.edu
Distribution: gnu
Organization: GNUs Not Usenet
Lines: 45