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 15:01:00 +0100
On Tue, Jul 22, 2025 at 2:18 PM Peter Bindels wrot:e:
>
> how do you like the name "lifetimebound" instead?


Yeah I'd be OK with [[lifetimebound]] or maybe one of these:

1. [[generates_temporary_handle]]
2. [[lifetime_bound]]
3. [[temporary_handle]]
4. [[object_lifetime_handle]]
5. [[handle_lifetime_bound]]
6. [[dependent_lifetime]]
7. [[transient_handle]]
8. [[lifetime_limited]]

I wonder should we limit it to return values? I mean sometimes we have
functions like this:

    bool MyClass::SomeMethod( Handle &p );

The programmer passes an uninitialised handle to 'SomeMethod', and
then the handle gets set by 'SomeMethod', like this:

    bool MyClass::SomeMethod( Handle &p )
    {
        static Handle h = 0u;
        p = ++h;
        return p != std::numeric_limits<Handle>::max();
    }

Received on 2025-07-22 14:01:14