c++gcccompiler-errorscompiler-warnings

GCC options: warning on non-void functions without a return statement


Is there 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;
}

Solution

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