When a function skips the return value, the compiler generates a warning, but not an error?

Here is the C ++ function:

int FuncWithoutReturn()
{
  int var = 10;
  ++var;
  // No return value here !!!
}

In MSVC, the compiler generates an error:

error C4716: "FuncWithoutReturn": value must be returned.

But in Xcode 5, the compiler just spits out a warning:

Control reaches the end of a non-void function

At runtime, if I'm lucky, the application crashes. I know this is a stupid mistake, but it would be nice for the compiler to give the error in the first place.

Just wondering, does anyone know why Xcode thinks this is a warning, not an error.

+4
source share
2 answers

-Werror=return-type, , . live.

clang gcc, , XCode .

undefined, , ++ 6.6.3 return 2, :

[...] ; undefined .

undefined ( ), .

+5

, -Werror=return-type

, - , XCode , , .

//xcconfig " " (aka GCC_WARN_ABOUT_RETURN_TYPE).

+2

Source: https://habr.com/ru/post/1527628/


All Articles