C++ Logo

std-proposals

Advanced search

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

From: Harald Achitz <harald_at_[hidden]>
Date: Fri, 30 Jun 2023 11:12:30 +0200
Yes, I am concerned about the first case, the second should not be
effected by _.

(void)f() ; is on the list of not allowed lines, since for security
reasons, use [[maybe_unused]] and add a comment why. Or, simply handle
the return value, if it is marked as [[nodiscard]], it is for a reason.

if auto _ = f(); becomes an alternative to (void)f(); it will land on
the forbidden list in some code bases, and a very useful feature , to
handle the second case where you just want the destructor run, is not
available.

And I think this can be a problem. I am aware that this will not effect
all code bases, but there will be some.

Regards, Harald

On 2023-06-29 17:01, Phil Endecott via Std-Proposals 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.
>
> Perhaps we really need two different attributes for the two cases?
>
>
> Regards, Phil.
>
>
>
>
>

Received on 2023-06-30 09:12:33