C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Named Return Value Optimisation [[nrvo]]

From: Jens Maurer <jens.maurer_at_[hidden]>
Date: Sun, 8 Feb 2026 13:06:40 +0100
On 2/8/26 01:55, Frederick Virchanza Gotham via Std-Proposals wrote:
> To achieve NRVO in C++, I think we need a happy medium between three things:
> (1) Good enough functionality and convenience for programmers

Sure.

> (2) Not too much hassle for compiler writers
> (3) Not too much complication for standards writers

Not among the primary goals of a proposal.
 
> I think the happy medium is to mark the return slot as follows:
>
> mutex Func(void)
> {
> [[nrvo]] mutex m;
> m.lock();
> return m;
> }

[... rules omitted ...]

How does this use of an attribute fit the idea that attributes
have optional semantics, given that the program will be ill-formed
without the attribute present?

Jens

Received on 2026-02-08 12:06:44