Jump to page: 1 2
Thread overview
[Issue 519] New: Invariant not called from autogenerated constructor
Nov 15, 2006
d-bugmail
Jan 10, 2009
d-bugmail
Jun 17, 2011
yebblies
Jun 20, 2011
Kenji Hara
Jan 22, 2012
yebblies
[Issue 519] Invariant not called from autogenerated class/struct constructor/destructor
Oct 30, 2012
Denis Shelomovskij
Nov 15, 2012
Don
November 15, 2006
http://d.puremagic.com/issues/show_bug.cgi?id=519

           Summary: Invariant not called from autogenerated constructor
           Product: D
           Version: 0.174
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Keywords: wrong-code
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla@digitalmars.com
        ReportedBy: deewiant@gmail.com


This code should fail regardless of whether the constructor is commented out or not:

class Foo {
        // this() {}
        invariant {
                assert (false);
        }
}

void main() {
        Foo foo = new Foo();
}

Yet, it only does if the constructor is explicitly specified. The invariant is not called from the automatically inserted constructor, even though there's no reason why it shouldn't be.


-- 

January 10, 2009
http://d.puremagic.com/issues/show_bug.cgi?id=519


smjg@iname.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |gim913@gmail.com




------- Comment #1 from smjg@iname.com  2009-01-10 11:30 -------
*** Bug 2184 has been marked as a duplicate of this bug. ***


-- 

June 17, 2010
http://d.puremagic.com/issues/show_bug.cgi?id=519


bearophile_hugs@eml.cc changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |bearophile_hugs@eml.cc


--- Comment #2 from bearophile_hugs@eml.cc 2010-06-17 13:08:26 PDT ---
*** Issue 4331 has been marked as a duplicate of this issue. ***

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


Andrei Alexandrescu <andrei@metalanguage.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |andrei@metalanguage.com
         AssignedTo|nobody@puremagic.com        |bugzilla@digitalmars.com


--- Comment #3 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-11-26 11:39:12 PST ---
The example needs parens:

class Foo {
    // this() {}
    invariant {
        assert (false);
    }
}

void main() {
    Foo foo = new Foo();
}

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



--- Comment #4 from Andrei Alexandrescu <andrei@metalanguage.com> 2010-11-26 11:39:39 PST ---
Forgot to add the actual parens :o).

class Foo {
    // this() {}
    invariant() {
        assert (false);
    }
}

void main() {
    Foo foo = new Foo();
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 17, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=519


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |yebblies@gmail.com


--- Comment #5 from yebblies <yebblies@gmail.com> 2011-06-17 07:53:50 PDT ---
What should happen in these cases?

class A
{
    shared invariant {}
}

class A
{
    immutable invariant {}
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 20, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=519


Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg@gmail.com


--- Comment #6 from Kenji Hara <k.hara.pg@gmail.com> 2011-06-20 05:45:02 PDT ---
Autogenerated destructor has same problem:
----
import core.stdc.stdio : printf;
class Foo {
    invariant() {
        printf("Foo.invariant\n");
    }
}
void main() {
    Foo foo = new Foo();
    printf("lifetime of foo\n");
    delete foo;
}
----

Should print:
----
Foo.invariant
lifetime of foo
Foo.invariant
----

But current output is:
----
lifetime of foo
----

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


yebblies <yebblies@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |devbai@mnet-mail.de


--- Comment #7 from yebblies <yebblies@gmail.com> 2012-01-22 12:21:31 EST ---
*** Issue 7334 has been marked as a duplicate of this issue. ***

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


Denis Shelomovskij <verylonglogin.reg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |verylonglogin.reg@gmail.com
            Summary|Invariant not called from   |Invariant not called from
                   |autogenerated constructor   |autogenerated class/struct
                   |                            |constructor/destructor


--- Comment #8 from Denis Shelomovskij <verylonglogin.reg@gmail.com> 2012-10-30 16:05:58 MSK ---
Structs have the same problem:
---
import std.stdio;

struct S
{
    invariant() { writeln("invariant"); } // never called
    // ~this() { writeln("~this"); } // uncomment to call invariant
}

void main()
{
    auto s = S();
}
---

-- 
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=519


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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |andrej.mitrovich@gmail.com


--- Comment #9 from Don <clugdbug@yahoo.com.au> 2012-11-15 00:20:52 PST ---
*** Issue 9019 has been marked as a duplicate of this issue. ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
« First   ‹ Prev
1 2