Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 25 - Segmentation fault on a simple template class; no segfault if substitute class by structure
Summary: Segmentation fault on a simple template class; no segfault if substitute clas...
Status: RESOLVED INVALID
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: 4.7.x
Hardware: x86_64 Linux
: --- normal
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2012-11-03 17:55 CET by Alexander Samoilov
Modified: 2012-11-04 14:44 CET (History)
2 users (show)

See Also:


Attachments
the code that segfaults (396 bytes, text/x-dsrc)
2012-11-03 17:55 CET, Alexander Samoilov
Details

Note You need to log in before you can comment on or make changes to this bug.
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.