https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80152

            Bug ID: 80152
           Summary: Not warning anymore about usage of uninitialized
                    variables
           Product: gcc
           Version: 7.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: slomo at coaxion dot net
  Target Milestone: ---

See below simple testcase

#include <stdio.h>

int main(int argc, char ** argv)
{
  int foo;

  if (argc == 1) {
    foo = 1;
  }

  foo += 1;

  printf("%d\n", foo);

  return 0;
}

foo is only initialized if argc==1, but gcc does not warn about the increment
of it or the usage as a printf() argument. This is with gcc 6.3.0, but the same
happens with 5.4.1 and 7.0.1.

I'm quite sure that in the past gcc warned about such cases and even more
complicated ones, and clang still does. There were false positives sometimes,
but those are less of a problem (just initialize the variable needlessly then)
than actual undetected usage of uninitialized variables.


Might be related to bug #78370, but the explanation there does not work here.
Before usage of foo no other function is called (and the explanation in that
bug seems rather far-fetched: while that would certainly be possible, whoever
writes such code will also be able to handle a wrong compiler warning... while
having that warning prevents mistakes in normal code).

Reply via email to