D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 380 - cannot use typeof(*this) in a static context
Summary: cannot use typeof(*this) in a static context
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P3 minor
Assignee: Walter Bright
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2006-09-27 12:21 UTC by Tomasz Stachowiak
Modified: 2014-02-15 13:20 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Tomasz Stachowiak 2006-09-27 12:21:58 UTC
struct Foo {
	alias typeof(*this) ThisType;
}


> 'this' is only allowed in non-static member functions
> can only * a pointer, not a 'int'



workaround:

struct Foo {
	alias typeof(*typeof(this).init) ThisType;
	static assert (is(Foo == ThisType));
}
Comment 1 Thomas Kühne 2006-09-29 02:05:36 UTC
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

d-bugmail@puremagic.com schrieb am 2006-09-27:
> http://d.puremagic.com/issues/show_bug.cgi?id=380

> struct Foo {
>         alias typeof(*this) ThisType;
> }
>
>
>> 'this' is only allowed in non-static member functions
>> can only * a pointer, not a 'int'
>
>
>
> workaround:
>
> struct Foo {
>         alias typeof(*typeof(this).init) ThisType;
>         static assert (is(Foo == ThisType));
> }

Added to DStress as
http://dstress.kuehne.cn/compile/t/typeof_10_A.d
http://dstress.kuehne.cn/compile/t/typeof_10_B.d
http://dstress.kuehne.cn/compile/t/typeof_10_C.d
http://dstress.kuehne.cn/compile/t/typeof_10_D.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFFHDPELK5blCcjpWoRAqm+AJ4jqtlQEQkV9fgRzRJXIiHDmaPcewCdHewk
7VoXDtrrI5FWYnS+LQgrKZ8=
=rMNb
-----END PGP SIGNATURE-----

Comment 2 Walter Bright 2006-11-25 03:51:37 UTC
Fixed DMD 0.175