是一个声明void(); 合法的,实际上是什么?

And*_*dré 8 c++ language-lawyer

我有一小段代码有一个声明 void();

int main() 
{
   void( ); // 1: parses fine in GCC 5.4.0 -Wpedantic 
   // void;    // 2: error declaration does not declare anything
} 
Run Code Online (Sandbox Code Playgroud)

什么是1 void()

  • 匿名函数声明?
  • 类型声明?
  • 一个空表达?

是什么让1 void()与2不同void;

我已经读过了:

  1. sizeof(void())是一个合法的表达式吗?但是void()被认为是sizeof中的一个类型
  2. decltype(void())中的void()究竟是什么意思?在declspec中考虑它.
  3. 我读的是无效{}合法与否?

但我很好奇松散的声明是否为void(); 不同于其中之一(当然为什么)

pee*_*rrr 0

一个void表情。

编译器不会为它创建任何代码,例如,

在VS中

_asm
{
    nop;
}
void();
_asm
{
    nop;
}
Run Code Online (Sandbox Code Playgroud)

产生这个组件:

_asm
{
    nop;
003017CE  nop  
}
void();
_asm
{
    nop;
003017CF  nop  
}
Run Code Online (Sandbox Code Playgroud)