using this instead of typeof(this)

Maxim Fomin maxim at maxim-fomin.ru
Tue Feb 26 09:21:50 PST 2013


On Tuesday, 26 February 2013 at 16:57:50 UTC, monarch_dodra wrote:
> On Tuesday, 26 February 2013 at 16:28:59 UTC, Ivan Kazmenko 
> wrote:
>> Hi!
>>
>> I have recently experimented with ways to express the exact 
>> instantiated type of a generic struct, and found that I can in 
>> some cases use "this" as that type.
>>
>> -----
>> 	this (ref this) // not a postblit constructor
>> 	this (ref this, this f, typeof (this), this, ref this g)
>> -----
>> Ivan Kazmenko.
>
> There was a discussion about this recently (wasn't it with 
> you?) and I believe the conclusion basically boiled down to 
> "bug: accepts-wrong".

That would be significant change in the language, where it is?

> Neither of those two signatures should compile. The fact that 
> they do is a bug.
>
> If they do compile, it's undefined behavior. From there, you 
> can't rely on anything.

Certainly this is not undefined behavior because those rely on 2 
language rules.

> I think there was a bugzilla entry for it, but I'll have to 
> look for it.



More information about the Digitalmars-d-learn mailing list