opAssign() still accepted for classes???

Alexander aldem+dmars at nk7.net
Fri Apr 29 07:43:56 PDT 2011


Doing some experiments, and after conversion of struct into a class I've found that opAssign(), contrary to what documentation says, is silently accepted for classes (in D 2.052)

What is worse, it segfaults when object is not constructed first:

---snip---
class X {
	int	v;

	typeof(this) opAssign(int i)
	{
		v = i;
		return this;
	}
}

void main()
{
	X x0 = new X();
	x0 = 0;			// ok
	X x1 = 0;		// segfault
}
---snip--

Well, I understand why it segfaults, but shouldn't opAssign() be disallowed? If documentation is wrong, and it is still valid for classes, this should be handled somehow else.

/Alexander


More information about the Digitalmars-d mailing list