Changeing return type of struct.toString()

Robert Jacques sandford at
Sun Feb 12 17:31:21 PST 2012

On Sun, 12 Feb 2012 12:36:47 -0600, Benjamin Thaut <code at> wrote:
> I'm currently trying to use D without a gc and didn't have major
> problems so far. A minor issues is that struct.toString() returns a
> string and this will almost allways leak memory when this is called.
> The question now is, can I change the return type of struct.toString()
> somewhere inside druntime or is it hardcoded in the compiler?
> It was possible without any problems to change the return type of
> Object.toString() and therefore every class in D because Object is the
> baseclass for every class. Is there something similar for structs?
> Kind Regards
> Benjamin Thaut

The primary users of toString() methods (struct or otherwise) are in std.format and std.conv, IIRC. I'd imagine that you'd be able to catch most uses via a correctly placed static assert.

More information about the Digitalmars-d mailing list