------- Comment #10 from mark at gcc dot gnu dot org  2009-09-08 12:33 -------
This is slightly annoying when used with -Wall -Werror. The following code
suddenly doesn't compile anymore. While a trivial rewrite, declaring the
variable and assigning it in the next statement, makes it build again this
doesn't really make sense IMHO since the code is identical (the original is
just more concise because it is one line).

int func(int i)
{
  int result = -1;
  if (i == 3)
    {
      result = 5;
      goto end;
    }

  int j = 16;
  /* Must be rewritten to to avoid warning/error with -Wall -Werror:
  int j;
  j = 16;
  */
  if (i > j)
    result = i;
  else
    result = j;

end:
  return result;
}

$ gcc -Wall -Werror -c -o jump.o jump.c 
cc1: warnings being treated as errors
jump.c: In function ‘func’:
jump.c:7:7: error: jump skips variable initialization
jump.c:20:1: note: label ‘end’ defined here
jump.c:10:7: note: ‘j’ declared here

gcc (GCC) 4.5.0 20090908 (experimental) [trunk revision 151507]


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40500

Reply via email to