gcc options: warning on non-void functions without

2019-02-18 08:39发布

问题:

Does anyone know a gcc/g++ option that generates an error/warning if there's a function that has a non-void return value but doesn't contain a return statement in its definition?

e.g.:

int add(int a, int b)
{
    a+b;
}

Many thanks in advance!

回答1:

-Wreturn-type. It's enabled by -Wall (which you should always be running with, along with -Werror -Wextra).