Why does GCC say “named return values no longer supported”?

前端 未结 3 1211
渐次进展
渐次进展 2021-02-01 14:15

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 w

相关标签:
3条回答
  • 2021-02-01 14:55

    This was a GCC extension, removed in GCC 3.4.

    0 讨论(0)
  • 2021-02-01 14:56

    See here

    They were removed in gcc3.4

    0 讨论(0)
  • 2021-02-01 15:08

    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.

    0 讨论(0)
提交回复
热议问题