I think I have observed a bug in the reporting of uninitialized
variables using -Wall .
As an example, this small program does not report any warnings:
#include <stdio.h>
int main(int argc, char *argv[])
{
int v1[1];
int *v2 = new int;
printf("%d\n", v1[0]);
*v2 = 1;
}
Why not?
An almost identical program does report the uninitialized variable:
#include <stdio.h>
int main(int argc, char *argv[])
{
int v1[1];
printf("%d\n", v1[0]);
}
~/gcc-6.2.0/bin/g++ -Wall -o foo foo.cpp
foo.cpp: In function ‘int main(int, char**)’:
foo.cpp:5:9: warning: ‘v1[0]’ is used uninitialized in this function
[-Wuninitialized]
printf("%d\n", v1[0]);
Why does removing the unrelated v2 variable cause g++ to correctly
warn of the uninitialized variable?
It is uninitialized in both cases and prints memory garbage:
./foo
1337669504
./foo
1830092400