C++ Logo

std-discussion

Advanced search

Re: About the description of [basic.life]/6

From: Tadeus Prastowo <tadeus.prastowo_at_[hidden]>
Date: Sun, 19 Apr 2020 03:28:59 +0200
On Sat, Apr 18, 2020 at 10:55 PM Andrew Schepler <aschepler_at_[hidden]> wrote:
>
> Got it. Linguistically, "the object will be or was located" is
> fairly vague, and it seems to me that the adverb clauses serve
> to specify the exact times meant by "will be" and "was". Using
> the definite article in "the object", rather than a phrase
> like "such an object", has to refer back to something recent,
> like the two phrases "an object" which are definitely modified
> by those time restrictions.

I interpret the "the object" in "any pointer that represents the
address of the storage location where the object will be or was
located" as an object that the pointer will point or already pointed.

> And in your interpretation, the "before ..., or after ..."
> conditions modify only the main clause of that same sentence,
> i.e. "any pointer that ... may be used, but only in limited
> ways"?

Yes.

> Then what are those limited ways it may be used, or the
> limitations on its use?

It is elaborated in the immediately following sentence. That sentence
in turn gives a forward reference to [class.cdtor].

> Does any other clause in the Standard
> elaborate that case, if the following sentences and paragraphs
> don't?

See my previous answer.

> To be very specific, an example:
>
> #include <string>
> #include <new>
> union U {
> int n;
> std::string s;
> U() {} // no member initialized
> ~U() {}
> };
> void f() {
> U u;
> std::string* p = new((void*) &u.s) std::string("hello");

Why do you need the cast to `void *' for `&u.s' ?

> p->~std::string();
> // The lifetime of the object p pointed at has ended, but its storage has not been reused or released.

Yes.

> // At this point, how can p be used and how may it not be used?

In accordance with Sentence-A, -B, and -C.

> *p; // ok?

Yes.

> }

-- 
Best regards,
Tadeus

Received on 2020-04-18 20:32:09