D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 7266 - [CTFE] Assign to ref param (that's taken from struct member) is noop
Summary: [CTFE] Assign to ref param (that's taken from struct member) is noop
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2012-01-10 19:47 UTC by Nick Sabalausky
Modified: 2012-01-14 17:41 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Nick Sabalausky 2012-01-10 19:47:50 UTC
-----------------------------------
import std.stdio;
struct S { int a; }

int foo()
{
	S s;
	return bar(s.a);  // A
	//bar(s.a); return s.a; // B
}

int bar(ref int b)
{
	b = 5;
	return b;
}

enum y = foo();

void main()
{
	writeln(y);
}
-----------------------------------

Expected output: 5
Actual output: 0

Same thing occurs with either the "// A" line or the "// B" line uncommented.  Also occurs with "out" instead of "ref".