[Issue 622] There should be a warning for unininitalized class reference

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Aug 8 09:46:41 UTC 2019


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

RazvanN <razvan.nitu1305 at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |WONTFIX

--- Comment #4 from RazvanN <razvan.nitu1305 at gmail.com> ---
This issue would may be solved in 2 ways:

1. Issue a warning whenever you have an initialized class reference.

This is not a valid solution because you may want an initialized class
reference that you will use later to point to another class instance.

2. Implement a dataflow analysis mechanism that will track all uses of f.

This is against dmd's principle of not doing complex dataflow analysis. Even it
we were to implement this, there would still be situations were you cannot be
sure whether you are dereferencing a null pointer:

class Foo
{
    int a;
}

void fun(Foo a);

void main()
{
    Foo f;
    fun(f);
    f.a;   // => cannot know what fun did to a.
}

In addition, this sort of access violation is extremely easy to solve because
you get a stack trace. Having a warning pointing it out is really redundant.

Closing as WONTFIX.

--


More information about the Digitalmars-d-bugs mailing list