gcc 选项:在没有 return 语句的非空函数上发出警告

是否有人知道 gcc/g++ 选项会在函数具有非 void 返回值但在其定义中不包含 return 语句时生成错误/警告?

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?

例如:

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

非常感谢!

推荐答案

-Wreturn-type.它由 -Wall 启用(您应该始终使用它,以及 -Werror -Wextra).

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

相关文章