Does returning to another void function from a void function is legal in C++?

Viewed 89

The C standard prohibit this. But I'm not sure what C++ standard says about this.

#include <iostream>

void bar() {
    std::cout << "From Bar" << "\n";
}

void foo() {
    std::cout << "From Foo" << "\n";
    
    return bar();
}

int main()
{
    foo();
    
    return 0;
}

The program compiles and works just fine. I like the style of return bar(); instead bar(); return;

Is this legal in C++11?

The answer below mentions that it's legal on latest draft.

1 Answers

Yes, this is allowed in C++. The standard says (quote from latest draft):

[stmt.return]

... A return statement with an operand of type void shall be used only in a function whose return type is cv void. ...

Related