Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error on missing return statement

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?

like image 773
Matt Joiner Avatar asked Aug 15 '10 10:08

Matt Joiner


1 Answers

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.

like image 139
Stephen Avatar answered Sep 20 '22 13:09

Stephen