Thread overview
[Issue 9019] New: invariant does not compile/run if class does not define constructor
Nov 14, 2012
Andrej Mitrovic
Nov 14, 2012
Maxim Fomin
Nov 15, 2012
Don
Nov 15, 2012
Andrej Mitrovic
November 14, 2012
http://d.puremagic.com/issues/show_bug.cgi?id=9019

           Summary: invariant does not compile/run if class does not
                    define constructor
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: nobody@puremagic.com
        ReportedBy: andrej.mitrovich@gmail.com


--- Comment #0 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-11-13 16:34:53 PST ---
class C
{
    invariant()
    {
        assert(0);
    }
}

void main()
{
    C c = new C();  // should fail after ctor invoked
}

C has an implicitly generated constructor, but the invariant isn't compiled or it doesn't run. If you add an explicit empty constructor then it does get added.

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


Maxim Fomin <maxim@maxim-fomin.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |maxim@maxim-fomin.ru


--- Comment #1 from Maxim Fomin <maxim@maxim-fomin.ru> 2012-11-14 04:40:52 PST ---
(In reply to comment #0)
> C has an implicitly generated constructor

Why? It seems there is no constructor in case like this.

> but the invariant isn't compiled or
> it doesn't run. If you add an explicit empty constructor then it does get
> added.

It is compiled but is not run because there is no ctor. The spec says that invariant is called when ctor completes but it does not say what happens when there is no ctor. You actually asking either create dummy ctor for cases like this or call invariant just after allocating class object which is not efficient - the first call to public function will abort the application anyway.

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


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

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


--- Comment #2 from Don <clugdbug@yahoo.com.au> 2012-11-15 00:20:52 PST ---
Duplicate of one of the oldest open bugs!

*** This issue has been marked as a duplicate of issue 519 ***

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



--- Comment #3 from Andrej Mitrovic <andrej.mitrovich@gmail.com> 2012-11-15 00:23:58 PST ---
(In reply to comment #2)
> Duplicate of one of the oldest open bugs!

Good thing it's assigned to someone, that means it will be fixed soon! Probably before new years eve 2006.

:P

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