为什么GCC会说“已命名返回值不再被支持”?

时间:2022-06-23 20:45:46

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

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

int id(int k) return k; { }

But GCC answered with a weird error message

但是GCC用一个奇怪的错误消息来回答

error: named return values are no longer supported

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

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

谁能解释一下这个奇怪的功能是什么吗?我从来没听说过。

3 个解决方案

#1


38  

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

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

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

这里添加了对NRVO的本地支持,但没有扩展——GCC 3.1发布系列。

Brief cut and paste for context:

简单剪切粘贴上下文:

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

g++现在支持“命名返回值优化”:对于类似的代码

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.

G+将在返回值槽中分配a,这样返回就变成了no-op。要使其工作,函数中的所有返回语句必须返回相同的变量。

#2


4  

See here

在这里看到的

They were removed in gcc3.4

它们在gcc3.4中被移除

#3


2  

This was a GCC extension, removed in GCC 3.4.

这是一个GCC扩展,在GCC 3.4中删除。

#1


38  

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

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

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

这里添加了对NRVO的本地支持,但没有扩展——GCC 3.1发布系列。

Brief cut and paste for context:

简单剪切粘贴上下文:

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

g++现在支持“命名返回值优化”:对于类似的代码

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.

G+将在返回值槽中分配a,这样返回就变成了no-op。要使其工作,函数中的所有返回语句必须返回相同的变量。

#2


4  

See here

在这里看到的

They were removed in gcc3.4

它们在gcc3.4中被移除

#3


2  

This was a GCC extension, removed in GCC 3.4.

这是一个GCC扩展,在GCC 3.4中删除。