www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4371] New: template tuple [misuse?] segfault

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

           Summary: template tuple [misuse?] segfault
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: ellery-newcomer utulsa.edu



21:36:24 PDT ---
The code:

struct s(T ...){
}
alias s!("hi!") t;
static if(is(t U == s!(U))){
}   
void main(){
}


The fireworks:

Segmentation fault (core dumped)

on compile.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 22 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4371


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |patch



There are two issues:
(1) deduceType() can return a tuple. This causes the segfault, because it isn't
a type.
Fixing that stops the crash, but the code still doesn't work, because...
(2) Same as bug 5164: it shouldn't try to add the symbol twice. Exactly the
same fix works here.

PATCH: expression.c, line 5185, IsExp::semantic().
----------
Lyes:
    if (id)
    {
-        Dsymbol *s = new AliasDeclaration(loc, id, tded);
+        Dsymbol *s;
+        if (isTuple(tded))
+            s = new TupleDeclaration(loc, id, &(isTuple(tded)->objects));
+        else 
+            s = new AliasDeclaration(loc, id, tded);
        s->semantic(sc);
-        if (!sc->insert(s))
-            error("declaration %s is already defined", s->toChars());
        if (sc->sd)
            s->addMember(sc, sc->sd, 1);
+        else if (!sc->insert(s))
+            error("declaration %s is already defined", s->toChars());
    }
    //printf("Lyes\n");
    return new IntegerExp(loc, 1, Type::tbool);

Lno:
    //printf("Lno\n");
    return new IntegerExp(loc, 0, Type::tbool);

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


Don <clugdbug yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|ice-on-invalid-code         |ice-on-valid-code
            Summary|segfault(template.c)        |segfault(template.c)
                   |template tuple [misuse?]    |template tuple in is()
                   |                            |expression
         OS/Version|Linux                       |All



And the code was valid.

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




There's something wrong with the patch.

This part breaks Phobos unit tests:

-        if (!sc->insert(s))
-            error("declaration %s is already defined", s->toChars());
        if (sc->sd)
            s->addMember(sc, sc->sd, 1);
+        else if (!sc->insert(s))
+            error("declaration %s is already defined", s->toChars());

Changing the first of those lines to:

        if (!isTuple(tded) && !sc->insert(s))
            error("declaration %s is already defined", s->toChars());

allows the test code to compile. But I don't really understand why it should be
necessary. Possibly it's another bug which is being triggered.

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


Walter Bright <bugzilla digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |bugzilla digitalmars.com
         Resolution|                            |FIXED



12:44:18 PST ---
Commit pushed to master at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/a48c43c9e3b7dc57092c1a72c1e019c46178f11b

Commit pushed to dmd-1.x at https://github.com/D-Programming-Language/dmd

https://github.com/D-Programming-Language/dmd/commit/999ef822efdca31c6983ea89805b178526c53c3d

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