Bug 7334 – autogenerated CTOR don't check invariant

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2012-01-21T09:07:00Z
Last change time
2012-01-21T17:21:31Z
Assigned to
nobody
Creator
devbai

Comments

Comment #0 by devbai — 2012-01-21T09:07:46Z
Hello 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() // {} @property { public int value() const { return mValue; } public void value(int newValue) { mValue = newValue; } } invariant() { 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:"); writeln(aObject.value); } ************** compiled with "DMD64 D Compiler v2.057" and run will shown this output: ************** core.exception.AssertError@src/bug/bugNoInvariantCheckWithAutoCTOR/TestAppBugNoInvariantCheckWithAutoCTOR.d(24): NOT mValue>0 ---------------- (_d_assert_msg+0x1f) [0x448323] ./(void TestAppBugNoInvariantCheckWithAutoCTOR.ClassA.__invariant()+0x5e) [0x443f46] ./(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/libc.so.6(__libc_start_main+0xfe) [0x7ffe8348ed8e] ---------------- creating ClassA reading value: checking INVARIANT ClassA (mValue: 0) ************** I would expect that the assert should throw an Error during the ctor.
Comment #1 by yebblies — 2012-01-21T17:21:31Z
*** This issue has been marked as a duplicate of issue 519 ***