C++ Logo

std-discussion

Advanced search

Re: Wording Includes Normal Use Case

From: Daniel Markus <daniel_at_[hidden]>
Date: Fri, 24 Nov 2023 19:42:19 +0000
Perhaps I've misunderstood this completely.
To me, according to ยง6.7.3/9 the following program is undefined behavior.

struct S
{
   ~S() {}
};

int main()
{
   S s1;
   S s2; // "another object of the original type does not occupy that same storage location"
   return 0;
}

Best regards,
Daniel


________________________________
From: Std-Discussion <std-discussion-bounces_at_lists.isocpp.org> on behalf of Brian Bi via Std-Discussion <std-discussion_at_[hidden]>
Sent: Friday, November 24, 2023 04:31
To: Jens Maurer <jens.maurer_at_[hidden]>
Cc: Brian Bi <bbi5291_at_[hidden]>; std-discussion_at_[hidden]ocpp.org <std-discussion_at_[hidden]>
Subject: Re: [std-discussion] Wording Includes Normal Use Case



On Thu, Nov 23, 2023 at 4:25 PM Jens Maurer <jens.maurer_at_[hidden]<mailto:jens.maurer_at_[hidden]>> wrote:


On 23/11/2023 21.50, Brian Bi wrote:
>
>
> On Thu, Nov 23, 2023 at 2:43 PM Jens Maurer via Std-Discussion <std-discussion_at_[hidden]<mailto:std-discussion_at_[hidden]> <mailto:std-discussion_at_[hidden]<mailto:std-discussion_at_[hidden]>>> wrote:
>
>
> On 23/11/2023 19.42, Daniel Markus via Std-Discussion wrote:
> > Maybe I'm picky and probably everyone understands what is meant, but
> > what's said right now is that the (an) other object occupies its own
> > storage location, which is the normal use case.
>
> There is half a sentence in front that talks about ending the lifetime
> prior to the implicit destructor call, and there is an example that follows.
>
> What exactly is unclear here?
>
>
> I think the issue is that the normative wording is not clear about the temporal relationship, i.e., that the UB only occurs if the ending of the lifetime (without subsequent recreation of an object of the same time) happens /before/ the implicit destructor call---as opposed to when you do nothing and just let the implicit destructor call take place (in which case the ending of the lifetime occurs at the same time as the implicit destructor call, because the start of the implicit destructor call ends the lifetime).

Aha. Maybe we want to make this a note and rely on [stmt.dcl] p2
and [basic.life] p7.2 instead?

Yeah, I agree that it should be a note. In terms of references, it seems like you'd have to throw in [basic.start.term] p1 and p2 as well.


Jens


--
Brian Bi

Received on 2023-11-24 19:42:22