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