Bug 132 – class template, alias and class inheritance combo leads to segfault

Status
RESOLVED
Resolution
FIXED
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
Linux
Creation time
2006-05-10T05:12:00Z
Last change time
2014-02-15T13:21:28Z
Keywords
wrong-code
Assigned to
bugzilla
Creator
larsivar

Comments

Comment #0 by larsivar — 2006-05-10T05:12:49Z
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.
Comment #1 by larsivar — 2006-05-10T05:23:11Z
The bug showed up with DMD 0.150, but I upgraded to 0.156 before finding this minimal test.
Comment #2 by benoit — 2006-05-10T15:23:48Z
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"); }
Comment #3 by benoit — 2006-05-10T15:44:56Z
(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 { public this(){ 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.
Comment #4 by bugzilla — 2006-05-25T04:23:18Z
Fixed 0.158