www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18313] New: Default initializer for class isn't always called

https://issues.dlang.org/show_bug.cgi?id=18313

          Issue ID: 18313
           Summary: Default initializer for class isn't always called
           Product: D
           Version: D2
          Hardware: x86
                OS: Windows
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: skocznymr gmail.com

When working with dlib library (gamedev oriented library) I've noticed a
strange behaviour, which seems unexpected to me:

For this example code (add "dlib": "~>0.12.2" to dub dependency to build):

import std.stdio;
import dlib.math;

class Foo
{
        Matrix4f mat1;
        Matrix4f mat2 = Matrix4f.zero();
        Quaternionf q1;
        Quaternionf q2 = Quaternionf.identity();;
}

void main()
{
        Foo foo = new Foo();
        writeln(foo.mat1);
        writeln(foo.mat2);
        writeln(foo.q1);
        writeln(foo.q2);

        Matrix4f mat3;
        Matrix4f mat4 = Matrix4f.zero();

        writeln(mat3);
        writeln(mat4);
}

The expectation is that foo.mat2 gets initialized to Matrix4f.zero() value,
just like it works with foo.q2 and mat4 variable. But for some reason, foo.mat2
stays uninitialized (filled with NaNs rather than zeroes).

--
Jan 27