Question: Unlike Java, in C/C++ the following is **allowed**:

```
int* foo ()
{
  if(x)
    return p;

  // What if control reaches here?
}

```

This often causes crashes and it is hard to debug problems. Why doesn't the *standard* enforce to have a **final return** for non-`void` functions? (Compilers generate an error for a wrong `return` value.)

Is there a flag in GCC or [MSVC](https://en.wikipedia.org/wiki/Microsoft_Visual_C%2B%2B) to enforce this? (something like `-Wunused-result`)

Answer: 
You can convert the warning into an error by using the following compiler options 

`-Wreturn-type -Werror=return-type`. 

Check out This [link](https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html)
As far as I remember, Visual Studio 2008 warns you about a "execution path that does not have a return value". It is allowed in the meaning of that "C++ won't stop you from shooting you in the foot". So you are to think, not the compiler.