Package: gcc-3.4 Version: 3.4.2-2 Severity: normal
It seems that if a function in a C program is declared "static", the type of the function is not void, the programmer forgets to add a "return" statement, and one compiles the program with gcc using -O2, gcc gives no warning. Also it seems that -O3 gives a warning only if there is no return statement at all. It does not properly detect cases where control can reach end of function. Sample session follows. % cat foo.c static int foo(void) {} int main(void) { return foo(); } % cat bar.c static int foo(void) { if (0) { return 1; } } int main(void) { return foo(); } % gcc -Wall foo.c foo.c: In function `foo': foo.c:2: warning: control reaches end of non-void function % gcc -Wall -O1 foo.c foo.c: In function `foo': foo.c:2: warning: control reaches end of non-void function % gcc -Wall -O2 foo.c % gcc -Wall -O3 foo.c foo.c: In function `foo': foo.c:2: warning: no return statement in function returning non-void % gcc -Wall bar.c bar.c: In function `foo': bar.c:6: warning: control reaches end of non-void function % gcc -Wall -O1 bar.c bar.c: In function `foo': bar.c:6: warning: control reaches end of non-void function % gcc -Wall -O2 bar.c % gcc -Wall -O3 bar.c % gcc --version gcc (GCC) 3.4.2 (Debian 3.4.2-2) Copyright (C) 2004 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -- System Information: Debian Release: 3.1 APT prefers unstable APT policy: (500, 'unstable') Architecture: i386 (i686) Kernel: Linux 2.6.8-1-686 Locale: LANG=fi_FI, LC_CTYPE=fi_FI Versions of packages gcc-3.4 depends on: ii binutils 2.15-4 The GNU assembler, linker and bina ii cpp-3.4 3.4.2-2 The GNU C preprocessor ii gcc-3.4-base 3.4.2-2 The GNU Compiler Collection (base ii libc6 2.3.2.ds1-18 GNU C Library: Shared libraries an ii libgcc1 1:3.4.2-2 GCC support library -- no debconf information