🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

1 total messages Started by Paul Eggert Thu, 14 Sep 1989 01:29
`new T(I)' silently ignores I if T has no constructor
#420
Author: 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;
	}
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads