D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1950 - CTFE doesn't work correctly for structs passed by ref
Summary: CTFE doesn't work correctly for structs passed by ref
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: patch, wrong-code
Depends on:
Blocks:
 
Reported: 2008-03-26 16:52 UTC by Max Samukha
Modified: 2014-02-16 15:22 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Max Samukha 2008-03-26 16:52:58 UTC
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 Don 2009-08-17 02:13:20 UTC
This bug also applies to D1.0, replacing the 'enum' with 
const int x = foo();
Comment 2 Don 2009-08-21 00:20:15 UTC
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 Don 2009-08-25 00:52:15 UTC
I have sent Walter my patch for this, it will be in the next release.
Comment 4 Walter Bright 2009-09-03 13:23:39 UTC
Fixed dmd 1.047 and 2.032