🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

2 total messages Started by casey Thu, 06 Oct 1988 00:21
GNU C++ 1.27 does not call destructors for temporaries
#1478
Author: casey
Date: Thu, 06 Oct 1988 00:21
73 lines
1951 bytes
VERSION:
	GNU CC 1.27
	GNU C++ 1.27
	GNU LIBG++ 1.25

CLIENT MACHINE:
	VAX 8350

CLIENT OPERATING SYSTEM:
	ULTRIX 2.2 - no patches installed

SYNOPSIS:
	The GNU C++ compiler automatically allocates temporaries for
	expression evaluation.  It properly calls constructors for the
	class of the temporaries, but doesn't call destructors for
	them.

REPEAT-BY:
	The following program demonstrates the problem.  No fix yet,
	but we'll start looking immediately because we can't proceed
	with our work until this is fixed.  If anyone comes up with
	a fix please mail us a copy.  Thanks!

-----
char *malloc(unsigned int);

/*
 * CLASS FOO
 */
class foo {
	int *store;
public:
	foo(int);
	~foo(void);
	friend foo operator+(foo &, foo&);
};

inline foo::foo(int n)			/* FOO CONSTRUCTOR */
{
	puts("foo constructor");
	store = (int *)malloc(sizeof(*store));
	if (store)
		*store = n;
	else
		perror("malloc");
}

inline foo::~foo(void)			/* FOO DESTRUCTOR */
{
	puts("foo destructor");
	if (store)
		free(store);
}

inline foo operator+(foo &a, foo &b)	/* FOO OPERATOR + */
{
	return(*a.store + *b.store);
}


/*
 * Trivial main program.
 *
 * GNU C++ generates a temporary of type foo to handle the expression to
 * compute the value of s.  A constructor for the temporary is properly
 * called, but a destructor for it is never called.  This is a bug.
 */
main()
{
	foo a(1), b(2), c(5);
	foo s = a + b + c;
}
Re: GNU C++ 1.27 does not call destructors for temporaries
#1481
Author: Doug Schmidt
Date: Thu, 06 Oct 1988 22:58
14 lines
1023 bytes
In article <16551@shemp.CS.UCLA.EDU> casey@CS.UCLA.EDU (Casey Leedom) writes:
[ code that breaks g++ 1.27 ]
>

>inline foo operator+(foo &a, foo &b)	/* FOO OPERATOR + */
>{
>	return(*a.store + *b.store);
>}
>

If you omit the inline on this function the destructor gets called
correctly. (But it is still seems like a bug!)

Doug
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