Thread overview
[Issue 1204] New: segfault using struct in CTFE
Apr 30, 2007
d-bugmail
May 07, 2007
d-bugmail
May 19, 2007
d-bugmail
Jul 01, 2007
d-bugmail
April 30, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1204

           Summary: segfault using struct in CTFE
           Product: D
           Version: 1.013
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: clugdbug@yahoo.com.au


Seems to be a memory corruption problem. Doesn't happen if unused, unused2 are removed.
---------
struct V {
    int a;
    int b;
}

V f()
{
    int q = 0;
    int unused;
    int unused2;
    return V(q, 0);
}

void main()
{
    const w = f();
}

==========================
Probably more helpful is this version, which prints:
No expression copy for: unused
just before it crashes.
------------------------
struct V {
    int a;
    int b;
}

V f()
{
    int q = 0;
    int unused;
    int unused2;
    return V(q, 0);
}

void main()
{
    const w = f().b;
}


-- 

May 07, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1204


thomas-dloop@kuehne.cn changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         OS/Version|Windows                     |All




------- Comment #1 from thomas-dloop@kuehne.cn  2007-05-07 00:18 -------
DMD-1.014 on Linux doesn't crash but results in incorrect values for V.a and V.b.

Added to DStress as http://dstress.kuehne.cn/run/s/struct_30_A.d http://dstress.kuehne.cn/run/s/struct_30_B.d http://dstress.kuehne.cn/compile/s/struct_30_C.d http://dstress.kuehne.cn/compile/s/struct_30_D.d


-- 

May 19, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1204





------- Comment #2 from baryluk@mpi.int.pl  2007-05-19 08:27 -------
Another example or problem with struct and char literals in CTFE:

import std.stdio;

struct Col2Spec {
        char[] type;
        char[] name;
}

char[] f() {
        char[] id = "x", id2 = "y";
        Col2Spec a = Col2Spec(id,"a"); // error in CTFE
//      Col2Spec a = Col2Spec("b",id2); // works
        int i = 2;
        assert(i - i, "Should be 'a', is " ~ a.name); // output, line: 13
        return "ret";
}

void main() {
        const static char[] w = f(); // line: 18
//      f(); // works
}

// sb.d(18): Error: cannot evaluate f() at compile time


-- 

July 01, 2007
http://d.puremagic.com/issues/show_bug.cgi?id=1204


bugzilla@digitalmars.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED




------- Comment #3 from bugzilla@digitalmars.com  2007-07-01 14:00 -------
Fixed DMD 1.018 and DMD 2.002


--