D-Scanner icon indicating copy to clipboard operation
D-Scanner copied to clipboard

False positive "unused var"

Open trikko opened this issue 9 years ago • 8 comments

Using IntelliJ Idea with Dscanner I get a tip: "Variable foo is never used"

void test()
{
    int foo;

    {
        foo = 1;
    }
}

trikko avatar Jan 18 '16 11:01 trikko

What did you use foo for in this example?

Hackerpilot avatar Jan 18 '16 19:01 Hackerpilot

To clarify: If I removed all lines referencing foo from that function, what would change?

Hackerpilot avatar Jan 18 '16 19:01 Hackerpilot

Ok, I misunderstood error message. The message says "not used" but i thought that "foo = 1" was an usage. Maybe it is "unread" :)

trikko avatar Jan 19 '16 11:01 trikko

So this wasn't an issue ?

ghost avatar Aug 05 '17 22:08 ghost

I think it is. Other ides report this warning as "never read".

trikko avatar Aug 06 '17 07:08 trikko

Yes but "never used" is not a false positive.

ghost avatar Aug 06 '17 09:08 ghost

Imo this is an unused var:

{ int a; ... }

In previous example it is used (assigned) but never read.

trikko avatar Aug 06 '17 11:08 trikko

Finding variables that are written to but never read is one of the purposes of this check. I'm tempted to close this as not a bug.

Hackerpilot avatar Aug 08 '17 23:08 Hackerpilot