Is this program ill-formed despite SFINAE?

后端 未结 2 1044
情话喂你
情话喂你 2021-01-21 13:08
template  void f() {
    return 0;  // returning value from function returning `void`
}

int main()
{
    // Not instantiating or calling any f

        
2条回答
  •  一生所求
    2021-01-21 13:28

    Reading more closely, that standard passage says:

    If a substitution results in an invalid type or expression, type deduction fails. An invalid type or expression is one that would be ill-formed if written using the substituted arguments. [..]

    return 0 is not an expression, so SFINAE does not apply.

    The passage goes on:

    Only invalid types and expressions in the immediate context of the function type and its template parameter types can result in a deduction failure.

    return 0 has nothing to do with the function type or its template parameter types, so SFINAE still does not apply.

提交回复
热议问题