Apparently gcc
has a long running problem with false negatives with this option see this bug report: Bug 18501 - [4.8/4.9/5 Regression] Missing 'used uninitialized' warning (CCP) and the long list of duplicates:
Duplicates: 30542 30575 30856 33327 36814 37148 38945 39113 40469 42724 42884 45493 46684 46853 47623 48414 48643 49971 56972 57629 58323 58890 59225 60444
Note from comment towards the end, we can see this has been an ongoing issue for over ten years:
This year will be the 10 year anniversary of this bug. We should order cake!
Note, if you remove the:
scanf("%d",&sec);
you will also receive a warning, Marc Glisse also points out removing the first four printf
also works as well (see it live). I don't see a similar example in the duplicates but not sure it is work adding yet another bug report for this.
Also see Better Uninitialized Warnings which says:
GCC has the ability to warn the user about using the value of a uninitialized variable. Such value is undefined and it is never useful. It is not even useful as a random value, since it rarely is a random value. Unfortunately, detecting when the use of an uninitialized variable is equivalent, in the general case, to solving the halting problem. GCC tries to detect some instances by using the information gathered by optimisers and warns about them when the option -Wuninitialized is given in the command line. There are a number of perceived shortcomings in current implementation. First, it only works when optimisation is enabled through -O1, -O2 or -O3. Second, the set of false positives or negatives varies according to the optimisations enabled. This also causes high variability of the warnings reported when optimisations are added or modified between releases.
A side note, clang
seems to catch this case just fine (see live example):
warning: variable 'sec' is uninitialized when used here [-Wuninitialized]
printf("sec = %d\n",sec);
^~~
As I note in a comment below at least this case seems to be fixed in gcc 5.0
.