为什么允许没有名字的声明?

Why is it allowed to have a declaration without a name?

在阅读标准时,我真的很惊讶地发现实际上名称在声明中是可选的:

struct Magic {};
int main() {
  int; // well-formed
  Magic; // well-formed
}

对于那些有兴趣阅读该标准的人,这是因为在 简单声明 中,init-declarator-list 是可选的。这是 demo.

所以我真的很想知道为什么允许这样做。我为什么要那样做?这对我来说真的毫无意义。我的理由是,如果它没有意义,为什么允许它?

根据 C++ 标准(7 个声明)

5 In a simple-declaration, the optional init-declarator-list can be omitted only when declaring a class (Clause 9) or enumeration (7.2), that is, when the decl-specifier-seq contains either a class-specifier, an elaborated-type-specifier with a class-key (9.1), or an enum-specifier....

因此这段代码

int main() {
  int; // well-formed
  Magic; // well-formed
}

格式错误。

此外,这些格式错误的声明在形式上是根据 3.1 声明和定义 部分第 2 段的定义,显然这样没有意义。