Where's the constructor?

The Red Fox ben@proximity.com.au
Wed Feb 11 00:47:00 GMT 1998


Here's an interesting situation:

I have a function:

String
foo()
{
	String bar = "la";
}

String is a reference counted 'canonical' class with default/copy
constructors defined and an = operator.

A compilation of this function produces a warning since there is no
return statement and the function is non-void.

This is fine  if the default constructor for the returned
string were called, but this does not seem to be the case.
As a result, the contents of the returned String will be garbage.

Surely in this case the default constructor for String should be called
in the absence of the return statement?

I am running g++ in egcs-1.0.1 on Linux 2.0.32 on a P100.
Compilation flags: -pipe -g -Wall -Wno-non-virtual-dtor
                   -fno-exceptions -fguiding-decls

Ben

+---------------------------------------------------------+
|\\ + //   Ben Ross                                \\ ^ //|
| \- -/    ben@proximity.com.au                     \` '/ |
|  \|/     http://www.proximity.com.au/~ben/         \~/  |
+---+-------------------------------------------------+---+




More information about the Gcc mailing list