Summary: autogenerated CTOR don't  check invariant
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD

--- Comment #0 from Devbai <> 2012-01-21 09:07:46 PST ---

I miss the invariant-check during the execution of 
the auto-generated ctor.

Following programm ....

import std.stdio;

class ClassA 
  private int mValue;

  // with the following default-CTOR would be the invariants be checked:
  // this()
  // {}

      public int value() const 
      { return mValue;

      public void value(int newValue)
      { mValue = newValue;

  { writeln("checking INVARIANT ClassA (mValue: ", mValue, ")");
    assert ( mValue>0, "NOT mValue>0");              

public static void main ()
  writeln("creating ClassA");
  ClassA aObject = new ClassA();   // may not pass;
                                   // because ClassA has no good CTOR
  writeln("reading value:");

compiled with "DMD64 D Compiler v2.057" 
and run will shown this output:

NOT mValue>0
(_d_assert_msg+0x1f) [0x448323]
./(void TestAppBugNoInvariantCheckWithAutoCTOR.ClassA.__invariant()+0x5e)
./(void invariant._d_invariant(Object)+0x20) [0x4489d0]
./(const(@property int function())
TestAppBugNoInvariantCheckWithAutoCTOR.ClassA.value+0x11) [0x443ea9]
./(_Dmain+0x50) [0x443f98]
./(extern (C) int rt.dmain2.main(int, char**).void runMain()+0x17) [0x44892f]
./(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x4484d6]
./(extern (C) int rt.dmain2.main(int, char**).void runAll()+0x42) [0x448982]
./(extern (C) int rt.dmain2.main(int, char**).void tryExec(scope void
delegate())+0x2a) [0x4484d6]
./(main+0xd3) [0x448467]
/lib/ [0x7ffe8348ed8e]
creating ClassA
reading value:
checking INVARIANT ClassA (mValue: 0)

I would expect that the assert should throw an Error during the ctor.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to