C++ Logo

std-proposals

Advanced search

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

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Wed, 11 Feb 2026 15:30:45 +0000
On Sun, Feb 8, 2026 at 6:34 PM Arthur O'Dwyer wrote:

> You're missing tests for what happens with templates like this:
> template<class T> void f() { [[gnu::nrvo]] T t; return t; }
> template void f<std::mutex>(); // certainly OK
> template void f<int>(); // this should be OK, even though `int` is not NRVO-able, right? Because otherwise templates become kind of unusable?
> At the moment, as I write this, your compiler crashes on this example.


I've fixed the ICE error. Also now you can just write [[nrvo]] instead
of [[gnu::nrvo]]. See here:

    https://godbolt.org/z/TbcEM368h

Received on 2026-02-11 15:31:04