www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Bug 132] New: class template, alias and class inheritance combo leads to segfault

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

           Summary: class template, alias and class inheritance combo leads
                    to segfault
           Product: D
           Version: 0.156
          Platform: All
        OS/Version: Linux
            Status: NEW
          Keywords: wrong-code
          Severity: critical
          Priority: P4
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: larsivar igesund.net


Given the following example:

--------------- badbug.d -------------

private import std.stdio;

class Foo : Bar {
}

class FooT(V){}

class Bar  {

    alias FooT!(int) BarT;

    public void foo() {
    }

}

void main( char[][] aCmdLineArgs )
{
    Foo fooIt = new Foo();
    if (fooIt !is null) writefln("fooIt should be valid");
    fooIt.foo();
    writefln("it worked");
}

---------------- end of file ------------

The program compiled with "dmd badbug.d" leads to a segfault or Access
Violation (depending on whether it is Linux or Windows, bug present on both
platforms, and with AFAICS all combinations of the compiler switches (-debug,
-release, -O and -inline) in fooIt.foo() method call.

 * Removing the alias remove the segfault.
 * Changing "class FooT(V)" to "template FooT(V)" removes the segfault
 * Moving the content of Bar into Foo removes the segfault
 * Using Bar directly removes the segfault
 * Removing Bar as Foo's superclass removes the segfault
 * Moving the alias below the foo method, removes the segfault
 * Moving Foo below Bar removes the segfault

I've set this to critical. The bug cropped up several places in the commercial
project I'm contracted for. It took me several hours to pin this down, and it
involved decimating 23 files in the process. Since the ordering of declarations
is important here, just removing an import was enough to remove the segfault.
In different places in the code where this cropped up (it was actually the same
function both places), the workaround turned out to be different for each place
and far from optimal, as it involved moving class declarations into relevant
files.


-- 
May 10 2006
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=132





------- Comment #1 from larsivar igesund.net  2006-05-10 05:23 -------
The bug showed up with DMD 0.150, but I upgraded to 0.156 before finding this
minimal test.


-- 
May 10 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=132


larsivar igesund.net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P4                          |P2




-- 
May 10 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=132


benoit tionex.de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |benoit tionex.de




------- Comment #2 from benoit tionex.de  2006-05-10 15:23 -------
Another variant of this bug. Here foo is not part of Bar, it is part of a
member variable. I guess this bug is very related to #106:

private import std.stdio;
class Foo : Bar { }
class FooT(V){
    public void foo() {}
}
class Bar {
    FooT!(int) f;
}
void main() {
    Foo fooIt = new Foo();
    if (fooIt !is null) writefln("fooIt should be valid");
    fooIt.f.foo();
    writefln("it worked");
}


-- 
May 10 2006
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=132





------- Comment #3 from benoit tionex.de  2006-05-10 15:44 -------
(In reply to comment #2)
 Another variant of this bug. Here foo is not part of Bar, it is part of a
 member variable. I guess this bug is very related to #106:
 
 private import std.stdio;
 class Foo : Bar { }
 class FooT(V){
     public void foo() {}
 }
 class Bar {

f = new FooT!(int); }
     FooT!(int) f;
 }
 void main() {
     Foo fooIt = new Foo();
     if (fooIt !is null) writefln("fooIt should be valid");
     fooIt.f.foo();
     writefln("it worked");
 }
 

I forgot to post the constructor for initializing the member f, but this changes nothing with the bug. --
May 10 2006
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/bugzilla/show_bug.cgi?id=132


bugzilla digitalmars.com changed:

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




------- Comment #4 from bugzilla digitalmars.com  2006-05-25 04:23 -------
Fixed 0.158


-- 
May 25 2006