Bug 4079 – [CTFE] Stack overflow from undetected circular reference
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2010-04-10T16:47:00Z
Last change time
2015-06-09T05:11:51Z
Keywords
CTFE, ice
Assigned to
nobody
Creator
bearophile_hugs
Comments
Comment #0 by bearophile_hugs — 2010-04-10T16:47:33Z
This is wrong D2 code:
int foo() {
assert(.r == 0);
return 0;
}
enum int r = foo();
void main() {}
dmd 2.043 shows a good enough error message (even if there's no need to print the second error two times):
test.d(2): Error: circular reference to 'r'
test.d(5): Error: cannot evaluate foo() at compile time
test.d(5): Error: cannot evaluate foo() at compile time
This is another wrong D2 program:
int foo() {
return r;
}
enum int r = foo();
void main() {}
But this time dmd 2.043 shows:
Stack overflow
Comment #1 by clugdbug — 2010-04-10T21:40:38Z
This looks similar to bug 2315, but I suspect the cause may be quite different.
Comment #2 by clugdbug — 2012-04-03T01:00:32Z
Fixed a couple of releases ago. Now on both D1 and D2, it displays a message like:
bug.d(42): Error: function bug.foo CTFE recursion limit exceeded
bug.d(43): called from here: foo()
bug.d(42): 1000 recursive calls to function foo
bug.d(45): called from here: foo()
and the first case doesn't have a repeated error message, it now displays:
bug.d(47): Error: cannot evaluate foo() at compile time. Circular reference?
bug.d(43): while evaluating r.init
bug.d(47): called from here: foo()