Why is g++ allowing me to treat this void-function as anything but?

前端 未结 2 1733

Why does the following compile in GCC 4.8 (g++)? Isn\'t it completely ill-formed?

void test(int x)
{
    return test(3);
}

int main() {}
         


        
2条回答
  •  爱一瞬间的悲伤
    2021-01-12 07:44

    That's allowed by the standard (§6.6.3/3)

    A return statement with an expression of type void can be used only in functions with a return type of cv void; the expression is evaluated just before the function returns to its caller.

提交回复
热议问题