I found out that the following code gets accepted by Visual C++ 2008 and GCC 4.3 compilers:
void foo()
{
}
void bar()
{
return foo();
}
Yes, it is valid code. This is necessary when you have template functions so that you can use uniform code. For example,
template
T f(int x, P y)
{
return g(x, y);
}
Now, g
might be overloaded to return void when the second argument is some particular type. If "returning void" were invalid, the call to f
would then break.