public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/105323] New: Unused assignment does not get reported
@ 2022-04-20 21:16 floridsleeves at gmail dot com
  2022-04-20 21:42 ` [Bug c/105323] assignment that is unused afterwards is not reported pinskia at gcc dot gnu.org
  2022-05-15  0:10 ` floridsleeves at gmail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: floridsleeves at gmail dot com @ 2022-04-20 21:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105323

            Bug ID: 105323
           Summary: Unused assignment does not get reported
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: floridsleeves at gmail dot com
  Target Milestone: ---

Hi, I'm trying to compile C program using gcc 9.4.0. The C program is:

#include<stdio.h>
int foo(int a)
{
    if(a==0)
        return 0;
    else
        return 1;//error
}
int main (int argc, char *arg[])
{
    int ret = 0;
    if(ret!=0) return 1;
    ret = foo(6);
    return 0;
}

The command I use to compile: gcc -Wunused test.c

The assignment 'ret = foo(6);' is unused. However, it's not reported by gcc.
Imagine if foo is a function that return error code to variable ret if it has
issues to execute, the error code will be unchecked. And gcc currently does not
even report such an unused assignment. Not sure it's a bug or implementation
choice. 


Output from `gcc --version`:
    gcc (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/105323] assignment that is unused afterwards is not reported
  2022-04-20 21:16 [Bug c/105323] New: Unused assignment does not get reported floridsleeves at gmail dot com
@ 2022-04-20 21:42 ` pinskia at gcc dot gnu.org
  2022-05-15  0:10 ` floridsleeves at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-04-20 21:42 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105323

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement
            Summary|Unused assignment does not  |assignment that is unused
                   |get reported                |afterwards is not reported
           Keywords|                            |diagnostic

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Currently set but unused only tracks if the variable is ever unused and not if
it is unused afterwards.

This requires data flow really to do such a warning.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug c/105323] assignment that is unused afterwards is not reported
  2022-04-20 21:16 [Bug c/105323] New: Unused assignment does not get reported floridsleeves at gmail dot com
  2022-04-20 21:42 ` [Bug c/105323] assignment that is unused afterwards is not reported pinskia at gcc dot gnu.org
@ 2022-05-15  0:10 ` floridsleeves at gmail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: floridsleeves at gmail dot com @ 2022-05-15  0:10 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105323

--- Comment #2 from Li Zhong <floridsleeves at gmail dot com> ---
Any further comment on this?
To do data flow analysis in local variable relatively costs less time and can
definitely help developers find more bugs like forgetting return value, etc.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-05-15  0:10 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-20 21:16 [Bug c/105323] New: Unused assignment does not get reported floridsleeves at gmail dot com
2022-04-20 21:42 ` [Bug c/105323] assignment that is unused afterwards is not reported pinskia at gcc dot gnu.org
2022-05-15  0:10 ` floridsleeves at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).