www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 6419] New: [CTFE] Cannot create a struct if it has a constructor (may cause ICE)

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6419

           Summary: [CTFE] Cannot create a struct if it has a constructor
                    (may cause ICE)
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Mac OS X
            Status: NEW
          Keywords: ice-on-valid-code, rejects-valid
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: kennytm gmail.com



Test case 1:
----------------------
static assert({
    struct Result {
        this(int x) {}
    }
    auto x = Result(1);  // <-- line 5
    return true;
}());
----------------------
x.d(5): Error: CTFE internal error assigning struct
x.d(7): Error: cannot evaluate delegate  system bool()
{
struct Result
{
    this(int x)
{
return this;
}
    void* this;
}
Result x = x = 0 , x.this(1);
return true;
}
() at compile time
...
----------------------





Test case 2 (causes ICE):

----------------------
static assert(({
    struct Result {
        this(int x) {}
    }
    return Result(1);
}(), true));
----------------------
x.d(6): Error: CTFE internal error assigning struct
Bus error: 10
----------------------


This bug affects using std.algorithm.map in CTFE, although I don't see any
point keeping that constructor any more.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 31 2011
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6419


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh gmail.com



*** Issue 6460 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6419


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug yahoo.com.au



This is because if the struct is nested, TypeStruct::defaultInitLiteral()
doesn't return a literal!

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 11 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6419


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|ice-on-valid-code           |
            Summary|[CTFE] Cannot create a      |[CTFE] Cannot create a
                   |nested struct if it has a   |nested struct if it has a
                   |constructor (may cause ICE) |constructor



The bug which caused an ICE was independent to this one, and has been fixed.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Aug 23 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6419


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs eml.cc



*** Issue 6653 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 29 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6419


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[CTFE] Cannot create a      |[CTFE] Cannot create a
                   |nested struct if it has a   |non-static nested struct
                   |constructor                 |
         OS/Version|Mac OS X                    |All



Actually, it doesn't need a constructor. The presence of _any_ member function
triggers the bug:

static assert({
    struct Result {
        void foo(){}
    }
    Result x;
    return true;
}());

If it doesn't have any member functions, then it is actually a static nested
struct. So true nested structs are never supported in CTFE.

It's because the hidden member of the struct needs a pointer to the enclosing
function, and this is not implemented.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 29 2011
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6419


ponce <aliloko gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |aliloko gmail.com



This is sad because you can't do compile-time FizzBuzz :)

-------------------
import std.stdio, std.conv, std.range, std.algorithm;

void main()
{
    enum fizzbuzz = iota(1, 100)
        .map!(x =>
            (0 == x % 15) ? "FizzBuzz" : 
            (0 == x % 5) ? "Buzz" : 
            (0 == x % 3) ? "Fizz" : to!string(x))
        .joiner("\n");
    writeln(fizzbuzz);
}
-------------------

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 02 2012
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=6419


Andrej Mitrovic <andrej.mitrovich gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich gmail.com
         Resolution|                            |WORKSFORME



15:17:48 PST ---
All the test-case provided here work in 2.061.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 08 2013