Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla

Bug 25

Summary: Segmentation fault on a simple template class; no segfault if substitute class by structure
Product: GDC Reporter: Alexander Samoilov <alexander.samoilov>
Component: gdcAssignee: Iain Buclaw <ibuclaw>
Status: RESOLVED INVALID    
Severity: normal CC: alexander.samoilov, art.08.09
Priority: ---    
Version: 4.7.x   
Hardware: x86_64   
OS: Linux   
Attachments: the code that segfaults

Description Alexander Samoilov 2012-11-03 17:55:26 CET
Created attachment 15 [details]
the code that segfaults

Dear Developers,

The following simple code produces segfault with both gdc 4.7 and latest dmd:
---------------------------------------------------------------------------
/*struct*/ class bits(int MSB, int LSB) {

    enum { msb  = MSB, lsb  = LSB, span = MSB-LSB+1, }

    static const ulong mask = (1L << span) - 1;

    ulong slice(ulong val) const { return ((val >> lsb) & mask); }
}

import std.stdio;
void main() {

    ulong a = 0xFEE0DDF00D;
    bits!(28,12) slicer;

    auto sliced = slicer.slice(a);
    writefln("slicer(28,12) : %X",slicer.slice(a));
}
---------------------------------------------------------------------------
There will not be segfault if substitute 'class' by 'struct' or declare
method bits::slice as static
(as 'static ulong slice(ulong val) { return ((val >> lsb) & mask);' } ).

Thanks,
Alexander
Comment 1 art.08.09 2012-11-04 09:44:26 CET
The D class reference ("slicer" in your code) is null and all methods in D are virtual (except private/final ones) - trying to call them with a null ref will fail - there's no compiler bug here.
Comment 2 Alexander Samoilov 2012-11-04 10:32:03 CET
Thanks for clarification.
Nice to hear that it isn't a compiler bug.