[Issue 780] New: The assignment of 'this' is allowed
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Sat Dec 30 18:50:44 PST 2006
http://d.puremagic.com/issues/show_bug.cgi?id=780
Summary: The assignment of 'this' is allowed
Product: D
Version: 0.178
Platform: PC
OS/Version: Windows
Status: NEW
Keywords: accepts-invalid
Severity: major
Priority: P2
Component: DMD
AssignedTo: bugzilla at digitalmars.com
ReportedBy: brunodomedeiros+bugz at gmail.com
The compiler allows assignment of the 'this' special reference. Instead 'this'
should be final (i.e., non assignable). In some cases, like in a class
constructor, 'this' is treated as if an inout reference, changing a variable in
another scope:
-------- --------
import std.stdio;
class Foo {
static bool first = true;
this() {
if(first){
first = false;
this = new Foo();
writefln("this= ", cast(void *)this);
}
}
}
void main(char[][] args) {
Foo foo = new Foo();
writefln("foo= ", cast(void *)foo);
}
-------- outputs: --------
this before= 8B0FE0
this after= 8B0FD0
foo= 8B0FD0
--
More information about the Digitalmars-d-bugs
mailing list