Is sizeof(int()) a legal expression?

房东的猫 提交于 2019-12-01 02:16:59
T.C.

No, sizeof( int() ) is ill-formed because int() is taken to be a type-id. Specifically, it's a function type, and sizeof cannot be applied to a function type.

[dcl.ambig.res]/2:

An ambiguity can arise from the similarity between a function-style cast and a type-id. The resolution is that any construct that could possibly be a type-id in its syntactic context shall be considered a type-id.

with this exact example given:

void foo(signed char a) {
    sizeof(int());                // type-id (ill-formed)
    sizeof(int(a));               // expression
    sizeof(int(unsigned(a)));     // type-id (ill-formed)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!