Error on missing return statement

2019-04-05 02:29发布

问题:

How do I generate an error for a missing return statement under GCC?

cpfsfuse.c:184: warning: no return statement in function returning non-void

I'm able to return errors for implicit function declaration (-Werror-implicit-function-declaration), and I'm aware of a -Werror= switch, but I can't locate an appropriate warning to promote to error status.

How can I achieve this?

回答1:

You should be able to use the -fdiagnostics-show-option option to show the correct flag for the Werror= switch. Taken from this blog post:

% gcc -x c -Wall -Wextra -fdiagnostics-show-option -c -o /dev/null - <<EOF
int foo() {
}
EOF
<stdin> In function ‘foo’:
<stdin>:2: warning: control reaches end of non-void function [-Wreturn-type]

Actually, it looks like the return-type flag may be the one you want.