Bug 13424 – [REG2.066] Initialization of delegate to do-nothing default causes segfault at runtime
Status
RESOLVED
Resolution
FIXED
Severity
regression
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2014-09-04T23:03:00Z
Last change time
2014-09-07T11:05:24Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
hsteoh
Comments
Comment #0 by hsteoh — 2014-09-04T23:03:21Z
I have a struct of delegates that I'd like to default to do-nothing stubs:
------
struct S {
void delegate(dchar ch) onChar = (dchar) {};
... /* other delegate variables similarly initialized */
}
------
It compiles, but crashes at runtime. Looking at the assembly code, it appears to be attempting to call an invalid pointer.
Comment #1 by czdanol — 2014-09-04T23:05:01Z
Please provide some test-case code example. :)
Comment #2 by hsteoh — 2014-09-05T16:16:19Z
Ah, sorry, forgot to post complete example. Here it is:
------
struct S {
void delegate(dchar) onChar = (dchar) {};
}
void main() {
S s;
s.onChar('a');
}
------
Strange, I just checked out v2.066.0 and it still compiles and gives me the segfault. Could it be a platform-specific bug?? I'm testing on Linux/64-bit.
Or maybe the tag isn't actually what was released? I'm confused.
Comment #6 by czdanol — 2014-09-05T21:51:22Z
Hmm, I tried it again under 2.066 and it now does the same thing as for you. I must have missed something last time checking. Looks like a bug :)