C++ Logo

std-proposals

Advanced search

Re: [std-proposals] A new C++ keyword: forget

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Thu, 13 Aug 2026 12:41:42 +0200
I think it is possible to start a new scope after each instruction and still have a syntactically and semantically correct program as you have shown. That gives a natural meaning and opening to shadow variables. But is it what the user really wants (if they care)?  - Regarding object lifetime: Delay destruction until the end of the scope. Having many more objects 'flying around' than names in the function. I tend to prefer, if the original variable is destructed at that time.  - Why reuse the names? That makes copy&paste easier. Or similar blocks, e.g. for return codes and error handling. But also leads to potential errors. A lot of dynamically typed languages allow it   -----Ursprüngliche Nachricht----- Von:David Brown via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Mi 12.08.2026 09:52 Betreff:Re: [std-proposals] A new C++ keyword: forget An:std-proposals_at_[hidden]; CC:David Brown <david.brown_at_[hidden]>; We could come a very long way with all this with three changes / additions to the language : 1. Allow a new variable declaration to shadow an exiting one, starting a new scope without having to open a new block.  Thus : int a = 1; do_something(a); int a = 2; do_something_else(a); double a = 3; do_another_thing(a); would mean the same as : int a = 1; do_something(a); { int a = 2; do_something_else(a); { double a = 3; do_another_thing(a); } }

Received on 2026-08-13 10:47:18