[Issue 4554] Cyclic constructor calls cause stack overflow

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Aug 13 22:51:02 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=4554


Don <clugdbug at yahoo.com.au> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |clugdbug at yahoo.com.au


--- Comment #1 from Don <clugdbug at yahoo.com.au> 2010-08-13 22:51:00 PDT ---
(In reply to comment #0)
> On this page:
> 
> http://www.digitalmars.com/d/2.0/class.html
> 
> It states "It is illegal for constructors to mutually call each other". This
> will compile and cause a stack overflow:
> 
> import std.stdio;
> 
> class C {
>     this() { this(1); }
>     this(int i) { this(); }    // illegal, cyclic constructor calls
> }
> 
> void main() {
>     C c = new C;
> }
> 
> object.Error: Stack Overflow
> 
> Isn't it possible to make this a compiler error? Or maybe this is a form of a
> halting-problem and can't be fixed? :)

I guess the compiler could set up a dependency tree of constructor calls, and
check for cycles. Quite a bit of work.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list