C++ Logo

std-proposals

Advanced search

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

From: Marcin Jaczewski <marcinjaczewski86_at_[hidden]>
Date: Tue, 10 Feb 2026 13:27:42 +0100
wt., 10 lut 2026 o 13:03 Alejandro Colomar
<une+cxx_std-proposals_at_[hidden]> napisał(a):
>
> Hi Marcin,
>
> On 2026-02-10T10:56:23+0100, Marcin Jaczewski via Std-Proposals wrote:
> > niedz., 8 lut 2026 o 19:34 Arthur O'Dwyer via Std-Proposals
> > <std-proposals_at_[hidden]> napisał(a):
> [...]
> > >> 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?
> > >
> > >
> > > It doesn't. Nobody likes the "ignorable attribute rule." See for example
> >
> > False, I like how they are handled :P
> > Only problem is people try sove in things that they should not.
>
> How do you feel about this?
>
> alx_at_devuan:~/tmp$ cat nodiscard.c++
> [[nodiscard]] int f(void);
>
> int
> main(void)
> {
> typeof(int (void) ) *fp1;
> typeof(int (void)[[nodiscard]]) *fp2;
>
> fp1 = &f; // I would expect a diagnostic here.
> fp1();
>
> fp2 = &f;
> fp2();
> }
> alx_at_devuan:~/tmp$ g++ -S -Wall -Wextra nodiscard.c++
> nodiscard.c++: In function ‘int main()’:
> nodiscard.c++:7:38: warning: ‘nodiscard’ attribute can only be applied to functions or to class or enumeration types [-Wattributes]
> 7 | typeof(int (void)[[nodiscard]]) *fp2;
> | ^
>
>

This is fine, the compiler sees that he can't fulfil his job and gives
you a warning.
This could be done by IDE or some external tool too.
I recall the goal was if you use attributes correctly then it does not
matter if the compiler recognizes it or not.
Like `[noreturn]` for correct code it does not matter if the compiler
generates some dead code as you can't observe it.
But for wrong code then you see diffrent results on diffrent
compilers. And I think this is acceptable.

> >
> > First of all, non-ignorable attributes should be explicit and ilformed
> > even if the compiler does not know them even in C++11.
>
> Agree.
>
> > I suggested adding the prefix `!!` for one like this, this could be
> > any symbol that makes C++11 reject this code and make this feature
> > backward and forward compatible.
>
> We already have non-ignorable attributes: scoped ones. This means that
> [[::attr]] is already the syntax for non-ignorable attributes. It only
> needs to be specified in the standard that the empty prefix is for the
> standard.
>
> > This will make a clear distinction between these two versions.
>
>
> Have a lovely day!
> Alex
>
> --
> <https://www.alejandro-colomar.es>

Received on 2026-02-10 12:27:57