C++ Logo

std-proposals

Advanced search

Re: [std-proposals] [PXXXXR0] Add a New Keyword ‘undecl’

From: wjf <wjf_at_[hidden]>
Date: Thu, 11 Dec 2025 09:11:07 +0800
The motivation of this proposal is to make this language more logically consistent and complete. As stated in the PDF, programmers can start the lifetime of a variable wherever they wish within a function, but cannot terminate it at the point they desire. This constitutes a form of incompleteness. And in practice, I use the work arround method a lot to use temporily variables in my own code. But I think they are ugly.


pdf link: https://github.com/zenkee/proposals/blob/main/Add_New_Keyword_undecl.pdf


wjf
wjf_at_[hidden]



        



         原始邮件
         
       
发件人:Jeremy Rifkin via Std-Proposals <std-proposals_at_[hidden]&gt;
发件时间:2025年12月11日 00:01
收件人:std-proposals <std-proposals_at_[hidden]&gt;
抄送:Jeremy Rifkin <jeremy_at_[hidden]&gt;
主题:Re: [std-proposals] [PXXXXR0] Add a New Keyword `undecl`



Hi,
It is extremely unlikely something like this would ever be added to C++. Such a change would require a lot of motivation,&nbsp;and this paper doesn't currently provide much motivation.


If the motivation is reusing the name, consider what rust has done with shadowing:
let x = foo();
let x = x.transform(); // new x shadows old x, can be a new type
There is precedent for this mechanism in C++ now with&nbsp;P2169.


If the motivation is compiler optimization, this is a micro-optimization and would be harmful as a language feature. Compilers can very easily identify when objects in a function are dead and reclaim storage and registers.


If the motivation is ending an object's lifetime as far as the C++ abstract machine is concerned and calling destructors, just use std::optional:
std::optional<T&gt; thing;
...
thing.reset(); // destroy the object, call the destructor
This is much more simple and straightforward to reason about than the language feature you're proposing. If you are concerned about the overhead from the flag std::optional stores to&nbsp;indicate if a value is contained or not, this is something compilers should be able to optimize with relative ease, though the overhead would be completely negligible in almost all cases even if it didn't.


Cheers,
Jeremy





On Tue, Dec 9, 2025 at 8:23 PM wjf via Std-Proposals <std-proposals_at_[hidden]&gt; wrote:
see attachment


wjf
wjf_at_[hidden]



--
 Std-Proposals mailing list
 Std-Proposals_at_[hidden]ocpp.org
 https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2025-12-11 01:11:14