According to the C++23 standard, what is the output of this program?
#include <iostream>
int f()
{
std::cout << 1;
}
int main()
{
f();
std::cout << 2;
}f() is missing a return statement, but this is not a compilation error.
The program is (or may be) undefined
This is not a compilation error, but undefined behaviour. According to §[stmt.return]¶4 in the standard:
Flowing off the end of a constructor, a destructor, or a non-coroutine function with a cv
voidreturn type is equivalent to areturnwith no operand. Otherwise, flowing off the end of a function that is neithermain(§[basic.start.main]) nor a coroutine (§[dcl.fct.def.coroutine]) results in undefined behavior.