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@lists.isocpp.org>
Gesendet: Mi 12.08.2026 09:52
Betreff: Re: [std-proposals] A new C++ keyword: forget
An: std-proposals@lists.isocpp.org;
CC: David Brown <david.brown@hesbynett.no>;
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);
}
}