C++ Logo


Advanced search

Re: [std-proposals] New function attribute [[nodiscard_scope]]

From: Frederick Virchanza Gotham <cauldwell.thomas_at_[hidden]>
Date: Fri, 30 Jun 2023 08:18:57 +0100
On Thu, Jun 29, 2023 at 10:37 PM Jason McKesson via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> ```
> some_func(g_obj.synchronize()); //Should only synchronize for the
> duration of the function call.
> ```

This is why I called it [[nodiscard_scope]]. It means that you don't
discard the return value, and also that you are careful about its
I think the following two should be permissible:

    some_func( g_obj.synchronize());

because the scoping of the return value is okay. The following should
be a warning/error though:

    auto &ref = *g_obj.synchronize();

because it obviously violates the intended scoping of the return value.

With regard to terminology, I think many people including myself
define the word 'object' as a synonym for 'variable' -- except that
the former is more typically used for classes, and that the latter is
used exclusively for intrinsic types (int, double, float, short,
etc.). That is to say, all variables are objects, but only some
objects are variables. But maybe the C++ Standard has a concise
definition of the two terms (it it has, I haven't read it).

Received on 2023-06-30 07:19:12