Memory error when using a template in a class destructor

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Jan 20 10:03:33 PST 2015


On Tue, 20 Jan 2015 17:59:38 +0000
JC via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com> wrote:

> The following code throws a 
> core.exception.InvalidMemoryOperationError@(0), anyone have an 
> idea of what is causing it?
> 
> ---
> 
> import std.stdio;
> 
> class Test
> {
> 	this()
> 	{
> 		struct Start
> 		{
> 			string filename;
> 		}
> 		Message!(Start)(Start("one.txt"));
> 	}
> 
> 	~this()
> 	{
> 		struct Stop
> 		{
> 			string filename;
> 		}
> 		Message!(Stop)(Stop("one.txt"));
> 	}
> }
> 
> unittest
> {
> 	auto t = new Test();
> }
> 
> struct Message(T)
> {
> 	this(T message)
> 	{
> 		writeln(typeid(T));
> 		writeln(message);
> 	}
`writeln` can allocate.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150120/88b1f7c3/attachment.sig>


More information about the Digitalmars-d-learn mailing list