C++ Logo

std-proposals

Advanced search

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

From: Thiago Macieira <thiago_at_[hidden]>
Date: Tue, 10 Feb 2026 12:13:26 -0800
On Tuesday, 10 February 2026 12:01:34 Pacific Standard Time Alejandro Colomar
wrote:
> Yup, that's the point. (Ignorable) attributes are very dangerous
> features as they are now, and could be turned into safety measures with
> very little change. But that change requires making them part of the
> actual language and type system.

Maybe. But then they need to be part of the type system so there are proper
rules on assignments and casting.

The two examples we've used so far ([[noreturn]] and [[reproducible]]) are
constraining attributes. So like noexcept or [[gnu::returns_nonnull]], you can
assign a function with such a constraint to a function pointer without: no
harm comes to you if you call a reproducible function more than once or have
exception handlers around code that will never throw.

Not all attributes will be constraining: some could be granting more rights
and should be handled the other way around: you can assign a function/value
without them to a pointer with them.

And some must be an exact match, like [[gnu::sysv_abi]] on Windows, __progmem
on AVR systems, or plain [[packed]].

The point being that [[ ]] attributes were not designed for this purpose. It
seems that we just want to use the syntax because it's there and does avoid a
number of other problems, instead of using proper keywords like noexcept.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-02-10 20:13:35