llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

-Wunused-variable false negative when variable is declared in if-condition

Open ec04fc15-fa35-46f2-80e1-5d271f2ef708 opened this issue 9 years ago • 9 comments

Bugzilla Link 31373
Version trunk
OS Linux
CC @mgehre,@pcc,@rnk,@ZequanWu

Extended Description

-Wunused-variable does not warn on this case:

bool f(); void g() { if (bool b = f()) { // ... } }

GCC's version of the warning does. Presumably we're marking the variable as 'used' in the condition handling code; while that's technically correct, it doesn't lead to the right outcome here.

while that's technically correct, it doesn't lead to the right outcome here.

Do you mean the right outcome should be that variables declared in condition expression of if/while/switch/for should not be marked as used or referenced?

ZequanWu avatar Jun 10 '20 04:06 ZequanWu

I think this must be a regression, I get the warning with clang 3.6.

pcc avatar Jun 23 '17 18:06 pcc

Is this issue still open? I would like to work on this but need some guidance as a first-time contributor.

abhilash42 avatar Jun 27 '22 19:06 abhilash42

Is this issue still open? I would like to work on this but need some guidance as a first-time contributor.

Yeah, this issue still open

image

eoan-ermine avatar Jul 10 '22 13:07 eoan-ermine

Hi, I am taking the issue and would like to work on it. I am going through the codebase, any headsup for approaching this issue!?

Krishna-13-cyber avatar Feb 21 '23 11:02 Krishna-13-cyber

I'd like to work on this.

NekoCdr avatar Aug 29 '23 18:08 NekoCdr

@Krishna-13-cyber do you still intend to work on this?

Endilll avatar Aug 29 '23 18:08 Endilll

Duplicate of #61681.

EugeneZelenko avatar Sep 01 '23 13:09 EugeneZelenko

As far as I can tell, the commit (https://github.com/llvm/llvm-project/commit/92023b15099012a657da07ebf49dd7d94a260f84) that fixed #61681 (which this issue was marked as a duplicate of even though this issue was created first) was reverted in https://github.com/llvm/llvm-project/commit/f0f395e00e2ec3f1f20ca9021d1554fde73d56c9 and I never saw it relanded, so I think this needs to be reopened. Please feel free to close this if that assessment is incorrect.

nathanchance avatar Jan 10 '24 19:01 nathanchance