[Bug 132] New: class template, alias and class inheritance combo leads to segfault

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed May 10 03:12:50 PDT 2006


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 at digitalmars.com
        ReportedBy: larsivar at 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.


-- 




More information about the Digitalmars-d-bugs mailing list