Thread overview
[Issue 4554] New: accepts-invalid Cyclic constructor calls cause stack overflow
Aug 01, 2010
Andrej Mitrovic
[Issue 4554] Cyclic constructor calls cause stack overflow
Aug 14, 2010
Don
Jan 29, 2012
Andrej Mitrovic
Jan 31, 2012
yebblies
Jan 31, 2012
Walter Bright
August 01, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4554

           Summary: accepts-invalid Cyclic constructor calls cause stack
                    overflow
           Product: D
           Version: D2
          Platform: Other
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2010-08-01 13:45:41 PDT ---
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? :)

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
August 14, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=4554


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

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


--- Comment #1 from Don <clugdbug@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: -------
January 29, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4554


Andrej Mitrovic <andrej.mitrovich@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


--- Comment #2 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-01-29 11:20:47 PST ---
Page now reads:
"It is illegal for constructors to mutually call each other, although the
compiler is not required to detect it."

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 31, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4554


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
                 CC|                            |yebblies@gmail.com
           Platform|Other                       |All
         Resolution|INVALID                     |
         OS/Version|Windows                     |All
           Severity|normal                      |enhancement


--- Comment #3 from yebblies <yebblies@gmail.com> 2012-01-31 14:21:19 EST ---
I think this is worth asking for.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
January 31, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=4554


Walter Bright <bugzilla@digitalmars.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|REOPENED                    |RESOLVED
                 CC|                            |bugzilla@digitalmars.com
         Resolution|                            |WONTFIX


--- Comment #4 from Walter Bright <bugzilla@digitalmars.com> 2012-01-31 01:22:00 PST ---
It's technically not a solvable problem in the general case. I think it's the halting problem.

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