为什么GCC说“不再支持命名的返回值”? [英] Why does GCC say "named return values no longer supported"?

查看:340
本文介绍了为什么GCC说“不再支持命名的返回值”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  int id(int k)return k; {} 

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


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


任何人都可以解释什么奇怪功能可能?我从来没有听说过。

解决方案

请参阅这里 - 通过在函数头中显式定义命名的返回值来实现早期NRVO。



本地支持NRVO已添加此处 - GCC 3.1系列版本。



简单剪切和粘贴上下文:


G ++现在支持命名的返回
值优化 / p>

  A f(){
A a;
...
return a;
}

G ++将在返回
值槽中分配一个,返回成为
a no-op。为了这个工作,所有返回
语句的函数必须返回
同一个变量。



I accidentally put the opening brace of my function definition after the return statement

int id(int k) return k; { }

But GCC answered with a weird error message

error: named return values are no longer supported

Can anyone please explain what that weird feature might be? I've never heard about it.

解决方案

See here - early NRVO implementation by explicit definition of the named return value in the function header.

Native support for NRVO without this extension was added here - GCC 3.1 Release Series.

Brief cut and paste for context:

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

A f () {
  A a;
  ...
  return a;
}

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.

这篇关于为什么GCC说“不再支持命名的返回值”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆