D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4099 - Inconsistent behaviour of ++/-- when mixing opUnary and 'alias this'.
Summary: Inconsistent behaviour of ++/-- when mixing opUnary and 'alias this'.
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, rejects-valid
Depends on:
Blocks:
 
Reported: 2010-04-17 05:13 UTC by a3471210
Modified: 2011-08-25 00:23 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description a3471210 2010-04-17 05:13:08 UTC
In the following example, ++x calls opUnary while x++ is performed on x directly:

struct X
{
	int x;
	alias x this;
	
	typeof(this) opUnary (string operator) ()
	{
		writeln ("operator called");
		return this;
	}
}
unittest
{	
	X x;
	++x; //operator called
	auto y = x++; //BUG! (alias this used. returns int)
}