GDCC icon indicating copy to clipboard operation
GDCC copied to clipboard

Warning for use of unconditionally uninitialized objects

Open DavidPH opened this issue 5 years ago • 0 comments

Code which reads an object which could not have been initialized prior to being read should issue a warning. Such as:

int i = i;
int i;
int j + i + 10;
int i;
if(i) {}

Tracking and warning for potentially uninitialized reads would be nice, but there would certainly be false positives. Still, if it proves reasonably simple, these should also issue a warning at high warn level:

int i;
if(cond())
   i = 10;
int j = i * 7;

The following, however, should not issue any warning:

void *p = &p; // Valid and well-defined.
int i, k;
int j = cond();
if(j)
   i = 10;
if(j)
   k = i + 6; // Has the same condition as the initialization.
else
   k = 42;
int i; // GDCC is not advanced enough to second-guess labels and goto usage.
label: if(i) {}

DavidPH avatar Apr 17 '19 14:04 DavidPH