Bug 10922 – Compiler segfaults when using __traits(parent, {})
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-08-29T12:01:00Z
Last change time
2014-01-04T23:27:36Z
Keywords
ice, pull
Assigned to
nobody
Creator
monkeyworks12
Comments
Comment #0 by monkeyworks12 — 2013-08-29T12:01:51Z
uint fib = (in uint n) pure nothrow {
enum self = __traits(parent, {});
return (n < 2) ? n : self(n - 1) + self(n - 2);
};
void main()
{
import std.stdio;
writeln(fib(39));
}
This code causes a segfault, as does giving fib the auto storage class instead of uint. If the code is changed to:
uint fib (in uint n) pure nothrow {
immutable self = __traits(parent, {});
return (n < 2) ? n : self(n - 1) + self(n - 2);
};
Then it does not segfault.
Comment #1 by yebblies — 2013-11-12T06:52:10Z
This one's interesting.
It gets to 9331 in expression.c and tries to run
error("forward reference to inferred return type of function call %s", toChars());
because it doesn't know the return type. But the call to 'self' has been optimzed to the entire function literal, including the call to 'self', infinitely.
The printing code needs to detect infinite recursive expressions and give up early.