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.
Comment #2 by k.hara.pg — 2013-11-16T03:43:07Z
Comment #3 by github-bugzilla — 2013-11-16T04:46:22Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/3371989030cedd3d58732fc423e68ce83a33e40c fix Issue 10922 - Compiler segfaults when using __traits(parent, {}) https://github.com/D-Programming-Language/dmd/commit/a86eb6c5702beff5fe786b0b2c6d5a954be85565 Merge pull request #2779 from 9rnsr/fix10922 Issue 10922 - Compiler segfaults when using __traits(parent, {})
Comment #4 by k.hara.pg — 2014-01-04T23:27:36Z
*** Issue 11848 has been marked as a duplicate of this issue. ***