www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 3488] New: Segfault(expression.c): enum declared with struct initializer in template

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

           Summary: Segfault(expression.c): enum declared with struct
                    initializer in template
           Product: D
           Version: 2.036
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Keywords: ice-on-valid-code
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: clugdbug yahoo.com.au



Reported by g in d.learn.
Segfaults in expression.c. D2 only.
--
struct Move{
    int Dx;
}
template genMove(){
    enum Move genMove = { Dx:4 };
}
enum Move b = genMove!();

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3488


g <sockpuppet3 hotmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sockpuppet3 hotmail.com



also to note that this also don't works:
--

struct A{
    int n;
}
template genA(){
    enum A genA = { n:4 };
}
immutable A b = genA!();

--

but this works:

--

struct A{
    int n;
}
template genA(){
    //works with immutable
    immutable  A genA = { n:4 };
}
immutable A b = genA!();

void main(){
    //ok
    assert(b.n == 4);
}
--

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3488


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|Segfault(expression.c):     |Segfault(expression.c):
                   |enum declared with struct   |enum declared with struct
                   |initializer in template     |static initializer



Further reduced test case shows it doesn't need a template.  It's just an enum
static initializer problem.
---
struct Move{
   int Dx;
}
enum Move genMove = { Dx:4 };
immutable Move b = genMove;
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 08 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3488




It's happening because static struct initializers with names are not evaluated
at compile time. And this is because init.c, StructInitializer::toExpression()
doesn't deal with it. BTW -- now that we have struct literals, I'm not sure
that we need struct initializers any more. They're a bit annoying,
implementation-wise.

--- TEST CASE ---
struct Move{ int Dx; }
immutable Move genMove = { Dx:4};
static assert(genMove.Dx == 4); // not evaluatable at compile time.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Nov 09 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=3488




PATCH: With the demise of struct initializers, it's not worth fixing properly.
But DsymbolExp::semantic() should check for a null value anyway (it checks in
other places in expression.c). This would prevent the segfault.

expression.c line 2306 (svn 267):

    if ((v->storage_class & STCmanifest) && v->init)
    {
        e = v->init->toExpression();
+          if (!e)
+        {   error("cannot make expression out of initializer for %s",
v->toChars());
+        e = new ErrorExp();
+        }
        e->semantic(sc);
        return e;
    }

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bugzilla digitalmars.com



01:19:02 PST ---
Changeset 349

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


Walter Bright <bugzilla digitalmars.com> changed:

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



22:44:36 PST ---
fixed dmd 2.040

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 30 2010