[Bug c/56391] New: variable set but unused isn't reported. if it has been used prior to setting it to a new value.
begnoc at gmail dot com
gcc-bugzilla@gcc.gnu.org
Tue Feb 19 10:51:00 GMT 2013
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56391
Bug #: 56391
Summary: variable set but unused isn't reported. if it has been
used prior to setting it to a new value.
Classification: Unclassified
Product: gcc
Version: 4.6.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: begnoc@gmail.com
#include <stdio.h>
#include <stdlib.h>
void release(void*);
void
release(void *ptr)
{
free(ptr);
ptr = NULL;
}
int
main(void)
{
int *a;
a = malloc(sizeof(int));
if(a == NULL){
perror("malloc");
return 1;
}
*a = 42;
printf("*a == %d\n", *a);
release(a);
if(a)
printf("*a == %d\n", *a);
return 0;
}
-------------------------------
Compiling this with "gcc -Wall -Wextra" doesn't report anything (should
be varible set but unused at line 10). This is clearly isn't what the
programmer intended and is easy to catch. Just reset the unused flag
after setting the variable.
This is also the case with g++.
More information about the Gcc-bugs
mailing list