Compiler bug? (alias sth this; and std.signals)

eskimo jfanatiker at gmx.at
Wed Nov 14 01:32:19 PST 2012


> 
> But wait! Due to "alias get this;", f.prop shouldn't copy prop
> but call get (which it does in the working - second - case)!
-> Also here the struct is copied, but the signal has no content yet and
thus no memory allocation yet occurred. (So no double free)
> 
> How to check? Remove the alias and writeln(f.prop) prints
> "Property(7)", with the alias writeln(f.prop) prints "7"

It should copy f.prop and it does. Your check results have another
explanation: writefln is a complete generic templated function, it has
no way of knowing that you want to pass the contained integer instead of
the struct. So by default it takes the struct (it has no requirements
that would lead to trigger the alias this). Eventually it will call some
function taking concrete arguments for printing the data. This concrete
function is not overloaded for your struct so the alias this to int
triggers now and the overload for int is being called. 

But first it is copied to every generic function that might be called on
the way.



More information about the Digitalmars-d mailing list