Dlang-UPB / D-scanner

Fork of the official D-scanner that uses dmd-as-a-lib
Boost Software License 1.0
6 stars 2 forks source link

replace libdparse in unused result visitor #74

Closed lucica28 closed 10 months ago

lucica28 commented 1 year ago

This check looks for situations where the return value of non-void functions is ignored. Example:

int fun() { return 1; }
void main()
{
        fun(); // [warn]: Function return value is discarded
}

In order to achieve that I decided to check CompoundStatement as this statement is encountered every time we have a set of instructions inside { }. Ex: for(...) {}, void f() {// CompoundStatement} and if we encounter directly a CallExp, it means that the return value is ignored.

I also checked instructions where we have only 1 statement, without { }, like:

if (true)
        foo()