No, it's not. Have a look at this answer for an explanation why compilers do not emit an error by default.
Anyway, if there's no return, the function's return value will just be undefined (garbage), and when you try to read it, you get undefined behavior.
looks like it's returning this pointer
What is actually returned depends on the calling convention used for your particular compiler and platform. If, for example, return values are pushed on the stack, the value you get might actually be some (now invalid) leftover data which was pushed on the stack during execution of the cout
statement. But it highly depends on very specific internals that you shouldn't need to be aware of most of the time - just remember that the return value will be garbage.
Now why are you able to do object.fun1().fun2()
? As @akappa explained in the comments, your member functions are non-virtual and do not access any members, so the compiler is very likely compiling them as free functions that don't require a this
pointer.
Many compilers have switches to warn you about missing returns, for example gcc has -Wreturn-type
, and it's also activated if you set -Wall
. Personally, I always define this warning to be treated as an error by setting -Werror=return-type
. It depends on your compiler, but it should have some functionality to enable this as well.