C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Dummy names for dummy objects

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Thu, 29 Jun 2023 12:07:59 -0400
On Thu, Jun 29, 2023 at 11:01 AM Phil Endecott via Std-Proposals
<std-proposals_at_[hidden]> wrote:
>
> Harald Achitz wrote:
> > Is the discussion about `auto _ = f()` actually done?
> >
> > Just asking since I still think it's a bad idea to allow that as a short
> > form to ignore return values for functions marked as [[nodiscard]]
>
> It seems to me that we are using [[nodiscard]] for two things. Sometimes
> the caller is expected to actually inspect the function return value;
> examples are functions that return success/error indications that should
> be checked, and functions where the user might be confused about whether
> it returns a result or modifies an in-out parameter.
>
> In other cases, the returned type is something with a non-trivial destructor
> and the requirement is only that it continues to exist to the end of
> the scope,
> rather than being discarded immediately; the obvious example is locks. This
> is less strict.

I'm not sure that the latter is in use. `unique_ptr` was not declared
`nodiscard`. A quick scan through the standard library suggests that
it, at least, doesn't use it for RAII objects. It uses it for things
like pointers returned from allocators and the like. There may be some
cases I missed, but I couldn't find an example of the type you
describe.

Received on 2023-06-29 16:08:10