Is sizeof(void()) a legal expression?

前端 未结 6 1647
暖寄归人
暖寄归人 2020-12-09 07:03

From [5.3.3/1], I found that:

The sizeof operator shall not be applied to an expression that has function or incomplete type

Fro

6条回答
  •  北海茫月
    2020-12-09 07:50

    From looking at CppReference.com - sizeof operator, the documentation literally states:

    sizeof cannot be used with function types, incomplete types, or bit-field glvalues.

    And since void() is a function type, then sizeof(void()) is not a legal expression.

    In their usage example, we can see their error comment on this line:

    std::cout << "size of function: " << sizeof(void()) << '\n'; // error
    

提交回复
热议问题