[Issue 7021] Structs with disabled default constructors can be constructed without calling a constructor.

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Sep 21 20:18:59 PDT 2012


http://d.puremagic.com/issues/show_bug.cgi?id=7021



--- Comment #13 from Kenji Hara <k.hara.pg at gmail.com> 2012-09-21 20:19:53 PDT ---
(In reply to comment #12)
> For structs, as long as there is no static opCall declared, S() and S.init
> should be identical, 

This is not already true for nested structs.

void main() {
    int g = 10;
    struct S {
        int n;
        auto foo(){ return g; }
    }
    auto s1 = S();  // StructLiteralExp
    assert(s1.tupleof[$-1] !is null);  // hidden ptr is filled
    assert(s1.foo() == 10);            // OK
    auto s2 = S.init;
    assert(s2.tupleof[$-1]  is null);  // hidden ptr isn't filled
    assert(s2.foo() == 10);            // Access Violation!
}

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


More information about the Digitalmars-d-bugs mailing list