Thread overview
[Issue 622] There should be a warning for unininitalized class reference
Aug 08, 2019
RazvanN
May 28, 2019
https://issues.dlang.org/show_bug.cgi?id=622

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|bugzilla@digitalmars.com    |razvan.nitu1305@gmail.com

--
May 28, 2019
https://issues.dlang.org/show_bug.cgi?id=622

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|D1 (retired)                |D2

--
May 28, 2019
https://issues.dlang.org/show_bug.cgi?id=622

Andrei Alexandrescu <andrei@erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Hardware|x86                         |All
                 OS|Windows                     |All

--
August 08, 2019
https://issues.dlang.org/show_bug.cgi?id=622

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

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

--- Comment #4 from RazvanN <razvan.nitu1305@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.

--