Bug 1950 – CTFE doesn't work correctly for structs passed by ref
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
x86
OS
Windows
Creation time
2008-03-26T16:52:00Z
Last change time
2014-02-16T15:22:33Z
Keywords
patch, wrong-code
Assigned to
nobody
Creator
samukha
Comments
Comment #0 by samukha — 2008-03-26T16:52:58Z
struct S
{
int x;
}
int foo()
{
S s;
bar(s);
return s.x;
}
void bar(ref S s)
{
s.x = 10;
}
enum x = foo();
static assert(x == 10); // Fails, x is 0
Comment #1 by clugdbug — 2009-08-17T02:13:20Z
This bug also applies to D1.0, replacing the 'enum' with
const int x = foo();
Comment #2 by clugdbug — 2009-08-21T00:20:15Z
I have fixed this in my copy of interpret.c, but it's rather more general. It allows arbitrary expressions as reference parameters. (Passing an array member by reference will result in wrong-code in DMD1.046).
Comment #3 by clugdbug — 2009-08-25T00:52:15Z
I have sent Walter my patch for this, it will be in the next release.