C++ Logo

liaison

Advanced search

Re: [wg14/wg21 liaison] labels

From: Jens Maurer <Jens.Maurer_at_[hidden]>
Date: Tue, 11 Aug 2020 23:02:53 +0200
On 11/08/2020 22.45, Uecker, Martin via Liaison wrote:
> Am Dienstag, den 11.08.2020, 16:41 -0400 schrieb Aaron Ballman:
>> On Tue, Aug 11, 2020 at 4:38 PM Uecker, Martin via Liaison
>> <liaison_at_[hidden]> wrote:
>>>
>>>
>>> BTW: Is
>>>
>>> if (x)
>>> int y;
>>>
>>> intentionally allowed in C++? Is there a sensible use
>>> case?
>>
>> Yes, that's well-formed C++ code. A possible use case would be for an
>> RAII object which performs work in its constructor or destructor (so
>> the declaration itself causes code to be executed).
>
> I understand this. I was thinking more about a
> high-level example where it would make sense to use
> it in this way.
>
> A file which is opened and immediately close again
> also does not make too much sense.

Maybe you wanted to create an empty file as some sort
of marker.

A declaration is just another kind of statement in C++;
a declaration may appear wherever a statement is allowed.

But it's certainly somewhat odd to give a name to
a variable and then never use that name.

In any case, the situation is certainly rare.

Jens

Received on 2020-08-11 16:06:29