为什么海湾合作委员会说"不再支持命名的返回值"?

Joh*_*itb 37 c++ gcc

我不小心把我的函数定义的左大括号放在return语句之后

int id(int k) return k; { }
Run Code Online (Sandbox Code Playgroud)

但GCC回答了一个奇怪的错误消息

错误:不再支持命名返回值

任何人都可以解释这个奇怪的功能可能是什么?我从来没有听说过.

Ste*_*end 39

请参阅此处 - 通过在函数头中显式定义命名返回值来实现早期NRVO.

此处添加对没有此扩展的NRVO的原生支持- GCC 3.1 Release Series.

简要剪切和粘贴上下文:

G++ now supports the "named return value optimization": for code like

A f () {
  A a;
  ...
  return a;
}
Run Code Online (Sandbox Code Playgroud)

G++ will allocate a in the return value slot, so that the return becomes a no-op. For this to work, all return statements in the function must return the same variable.