> 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).

Yes, it does. Both of the terms 'object' and 'variable' are defined in section 6 Basics.
There is a hole section that describes the Object Model https://eel.is/c++draft/intro.object

And the term variable is defined precisely at
https://eel.is/c++draft/basic#def:variable

Remark: variables can have an object type or a reference type (including reference to function); and a reference is not an object. Hence, it is not the case that all variable are objects.

> The following should
be a warning/error though:

    auto &ref = *g_obj.synchronize();

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

Could you elaborate on how it violates the intended scoping of the return value? I don't see what is the "intended scoping". Usually in c++, expression of lifetime is best expressed directly by defining objects in the appropriate scope.

Julien V.


On June 30, 2023 3:18:57 a.m. EDT, Frederick Virchanza Gotham via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
On Thu, Jun 29, 2023 at 10:37 PM Jason McKesson via Std-Proposals
<std-proposals@lists.isocpp.org> 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
scope.
I think the following two should be permissible:

some_func( g_obj.synchronize());
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).