C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Return Value Optimisation whenever you need it (guaranteed elision)

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Fri, 11 Aug 2023 15:22:27 +0200
pt., 11 sie 2023 o 15:02 Frederick Virchanza Gotham via Std-Proposals
<std-proposals_at_[hidden]> napisaƂ(a):
>
> I've written a paper on ensuring the elision of a move/copy operation
> when returning a class by value from a function. C++17 already ensures
> elision when it comes to Return Value Optimisation (RVO), but not when
> it comes to Named Return Value Optimisation (NRVO).
>
> Of the 27 platforms this is tested and working on, I've had to write
> implementations in assembler for 4 of them: arm64, m68k, hppa, sh4.
>
> I could spend another month on this paper but I need to think
> "progress not perfection" and release a draft. In the next draft I'll
> deal with:
> (1) Ensuring correct use of 'noexcept' with
> std::function<void(void)noexcept>
> (2) Use concepts or SFINAE to make sure the class is nonmovable
> and noncopyable
> No. 2 is important because some of the calling conventions will return
> in registers unless the class is unmovable and uncopyable.
>
> I have 27 workflows up on Github which show it tested and working on
> various operating systems, compilers and CPU's:
> https://github.com/healytpk/nrvo
>
> The PDF file of my paper is attached to this email, and you can also
> download the latest draft from:
>
> http://virjacode.com/downloads/nrvo/paper_nrvo_latest.pdf
>
> File attached: paper_nrvo_draft001.pdf

And all this proposal is to introduce the function `nrvo()`?
Are you aware that you waste your time on something that is
useless for everyone?
All you need to do is hack one compiler to remove
restrictions on not movable types in NRVO.
All logic should be present in any compiler that supports current NRVO.
```
Foo foo1()
{
   return Foo();
}
Foo foo2()
{
   Foo f;
   return f;
}
Mutex foo3()
{
   return Mutex();
}
Mutex foo4()
{
   Mutex f;
   return f;
}
```
All these functions should generate similar code and have the same
calling convention.
I even show link to article in previous discussion that show hack that
allow this
when you declare not defined copy constructor.

Received on 2023-08-11 13:22:38