Search code examples
cgccgcc-warning

-Wall without -Wreturn-type


According to the GCC manual, the -Wreturn-type options is enabled with -Wall. However, I can't find a proper way to disable it while keeping the rest of -Wall enabled.

Consider this code:

func() {}

If compiled without warnings, no output is produced. Now, if I turn on -Wall the following lines will appear:

$ gcc fn.c -Wall
fn.c:1: warning: return type defaults to ‘int’
fn.c: In function ‘func’:
fn.c:1: warning: control reaches end of non-void function

Ok, all nice. Now, if compiled with -Wreturn-type, the same output is produced:

$ gcc fn.c -Wreturn-type
fn.c:1: warning: return type defaults to ‘int’
fn.c: In function ‘func’:
fn.c:1: warning: control reaches end of non-void function

So, I conclude that -Wreturn-type is responsible for those warnings. But maybe it's not, or I'm doing something worse, as this was expected to produce no output:

$ gcc fn.c -Wall -Wno-return-type
fn.c:1: warning: return type defaults to ‘int’

Is it possible to use -Wall but disable -Wreturn-type completely? Or maybe I'm missing another available option?

If it matters, I'm on Mac OS 10.7 (Darwin 11) with GCC 4.2.1 (strangely enough, compiled with LLVM :P)


Solution

  • You can use -Wno-implicit-int to disable that warning:

    gcc -c -Wall -Wno-return-type -Wno-implicit-int fn.c
    

    However, this might cause other warnings that you might want to see to be disabled. For example, it'll suppress warning about a variable declared like so:

    static x = 1;
    

    Pick your poison.