D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4079 - [CTFE] Stack overflow from undetected circular reference
Summary: [CTFE] Stack overflow from undetected circular reference
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords: CTFE, ice
Depends on:
Blocks:
 
Reported: 2010-04-10 16:47 UTC by bearophile_hugs
Modified: 2015-06-09 05:11 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description bearophile_hugs 2010-04-10 16:47:33 UTC
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 Don 2010-04-10 21:40:38 UTC
This looks similar to bug 2315, but I suspect the cause may be quite different.
Comment 2 Don 2012-04-03 01:00:32 UTC
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()