C++ Logo

std-discussion

Advanced search

Re: Storage duration of temporary objects

From: Yongwei Wu <wuyongwei_at_[hidden]>
Date: Mon, 8 Dec 2025 00:47:56 +0800
On Sun, 7 Dec 2025 at 23:38, Brian Bi <bbi5291_at_[hidden]> wrote:

>
> On Sat, Dec 6, 2025 at 11:36 PM Yongwei Wu via Std-Discussion <
> std-discussion_at_[hidden]> wrote:
>
>> The good side is that it strengthens the idea that a temporary object
>> should have a storage duration, and even that it should be one of the
>> defined storage durations. However, if the temporary is not
>> lifetime-extended, the automatic storage duration does not really fit—
>> [basic.stc.auto] <https://eel.is/c++draft/basic.stc.auto> only describes
>> variables and scopes (as vs unnamed objects and full-expressions).
>>
>
> We already treat objects with automatic storage duration slightly
> differently depending on whether they're block variables or function
> parameters. We could potentially bring temporary objects (that are not
> lifetime-extended) within the same umbrella. Maybe that would simplify
> [class.temporary], or maybe not. Someone needs to volunteer for drafting.
>
>
>> So my feeling is that the standard is already trying to reconcile an
>> inconsistency in its language, but has not yet fully done so.
>>
>
> The CWG issue is: CWG1634
> <https://cplusplus.github.io/CWG/issues/1634.html>
>

Big thanks for the info. Good to know it is a known issue. I have searched
the standards several times for an answer, and thought it would be strange
that no one else thought it an issue. Sad to know it has been more than 20
years since it was first reported as CWG 365....

The issues may not be really significant, as it should mainly require
clarifications. It does make people wonder whether the four existing
storage durations apply to temporary objects. The answer seems to be a ‘No’
now.

-- 
Yongwei Wu
URL: http://wyw.dcweb.cn/

Received on 2025-12-07 16:48:10