C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Similar to [[no_discard]], but store in a variable, maybe call it [[must_store]]

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Tue, 22 Jul 2025 16:23:14 +0100
On Tue, Jul 22, 2025 at 3:23 PM Sebastian Wittmeier wrote:
>
> It is not something you can solve with 3 questions on this mailing list and a bit of bike-shedding on top.
>
> It is a task worthy of 5-10 PhD theses.
>
> (not saying one person cannot solve it).


Maybe a PhD was something big back in the 1900's; I think Albert
Einstein got his in 1905, but by the time I got to studying
electronics in the 2000's, I had one or two lecturers called 'Dr' who
really didn't have a firm grasp of what they were teaching. To be
honest in the future if I ever read through resumé's (or CV's) for job
applicants, I'll pay a lot more attention to "C++ committee" or "my
open-source repos on Github" or "the device I made to open my garage
door when the fire alarm goes off" than I would to 'Dr'. There's a few
programmers in the company I work for called 'Dr', and I still get
assigned the bugs they give up on, and my first response is always,
"I've never worked on this software before, I haven't a clue about how
it's supposed to work or what it's supposed to do, but if you want me
to find a segfault I'll find a segfault".

With regard to [[lifetimebound]], If we keep it to return values, then
the programmer would have to change:

    bool MyClass::SomeMethod( Handle &p );

to:

    Handle MyClass::SomeMethod( bool &error_code );

or perhaps even:

      std::pair<Handle,bool> MyClass::SomeMethod(void);

Or have a 'thread_local' variable something like
"last_myclass_error_code", and just have:

    Handle MyClass::SomeMethod(void);

I actually don't think this is that complicated. A thorough
description of the attribute [[lifetimebound]] would be something
like:

    "When applied to a class's method, the [[lifetimebound]] attribute
indicates that the invocation of the method on an object of the class
will return a value which is only valid for the lifetime of the
aforementioned object. Therefore where possible, the compiler shall
issue a diagnostic if it detects the use of the return value after the
aforementioned object has been destroyed."

I might write a paper about [[lifetimebound]], but right now No. 1 on
my To Do list is Paper Kernel C++, and No. 2 is to put out another
revision of p3357 renaming it to "std::prvalue" instead of
"std::factory". No. 3 on the list now is [[lifetimebound]] but we're
talking August-ish.

Received on 2025-07-22 15:23:28