Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does GCC say "named return values no longer supported"?

Tags:

c++

gcc

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.

like image 844
Johannes Schaub - litb Avatar asked Nov 22 '10 14:11

Johannes Schaub - litb


2 Answers

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.

like image 92
Steve Townsend Avatar answered Sep 20 '22 21:09

Steve Townsend


See here

They were removed in gcc3.4

like image 25
The Archetypal Paul Avatar answered Sep 21 '22 21:09

The Archetypal Paul