D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7032 - OpAssign is not called when this(this) is disabled
Summary: OpAssign is not called when this(this) is disabled
Status: RESOLVED INVALID
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-11-29 13:16 UTC by deadalnix
Modified: 2016-02-09 13:40 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 deadalnix 2011-11-29 13:16:21 UTC
As of http://digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=150299

If we disable this(this) in a struct, the opAssign member function should be used if it exists. Here is a sample code :

module fail2;

struct Fail {
	@disable
	this(this);
	
	ref Fail opAssign(ref const Fail t) {
		return this;
	}
}

int main(string[] argv) {
	Fail a;
	Fail b = a; // Error: struct fail2.Fail is not copyable because it is annotated with @disable
	
	return 0;
}
Comment 1 Kenji Hara 2016-02-09 13:40:59 UTC
OpAssign never work when a variable is initialized. In this line:

>	Fail b = a;

'b' is yet not born, but opAssign needs a living 'this' instance. Therefore, the variable 'b' initialization with an lvalue 'a' always tries to copy 'a', then rejected by @disable this(this).