C++ Logo

std-discussion

Advanced search

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

From: Andrew Schepler <aschepler_at_[hidden]>
Date: Sun, 19 Apr 2020 21:01:16 -0400
On Sun, Apr 19, 2020 at 7:18 PM Tadeus Prastowo <tadeus.prastowo_at_[hidden]>
wrote:

> On Sun, Apr 19, 2020 at 6:10 PM Andrew Schepler <aschepler_at_[hidden]>
> wrote:
> >
> > On Sat, Apr 18, 2020 at 9:29 PM Tadeus Prastowo <
> tadeus.prastowo_at_[hidden]> wrote:
> >>
> >> 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.
> >
> >
> > In the sentence "After a stolen car is found on private property, any
> person who has an ownership stake or financial responsibility for the
> property may be questioned by the police" does not imply every owner of
> property may be questioned, even on an intentional misreading.
>
> The word `may' when used in the standard has a different meaning than
> the word `may' that is used in the news.
>

True, but not my point. The question is what persons are described by the
noun phrase subject of that "may", whatever the "may ..." verb phrase might
say. Normally a definite noun phrase "the" <noun> which might be ambiguous
on its own but matches a recent noun identifies the same thing as that
previous noun, meaning any previous semantic attachments still apply to the
noun. (I even did it again in that last sentence.) So that's one reason I
had, but right now I'm more interested in the technical implications of
your understanding, not so much continuing to dig into this point.

>> > 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].
> >
> >
> > Sentence-Y does not describe p.
>
> By `p' you mean the pointer `p' in your example below? If so, indeed
> Sentence-Y does not apply to `p'.
>
> > The object it pointed at is not "under construction or
> > destruction".
>
> Do you mean the object pointed by the pointer `p' in your example
> below _after_ the statement `p->~std::string();' ? If so, yes, the
> statement is correct.
>
> > [class.cdtor]/1 does say no non-static member or
> > base class of *p can be referred to. But none of the rest of
> > [class.cdtor] can apply (except possibly paragraph 3, but its
> > restrictions would always be weaker than paragraph 1 if both
> > apply).
>
> It is irrelevant to discuss [class.cdtor] if you are referring to the
> pointer `p' in your example below _after_ the statement
> `p->~std::string();'.
>

Okay, I think we agree: In the union example after "p->~std::string();",
Sentence-Y does not apply to p. ([class.cdtor]/1 does apply, but on its own
standing, not because of Sentence-Y.)


> >> > 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' ?
> >
> >
> > It's a somewhat paranoid habit to protect against some other operator
> new definition which could be a better match than the one in <new>. The
> Standard describes a similar cast for the default behavior of
> std::allocator_traits<A>::construct. Of course if we take the example as a
> complete translation unit, that's not a concern.
>
> Noted. Thanks.
>
> >> > 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.
> >
> >
> > Wasn't that what you said applied to pb in the Standard example after
> the storage for the object it pointed at was reused? What is the difference
> in applicable Standard rules between pb and this p? Or what other normative
> effect, if any, does the word "reused" in Sentence-X have?
>
> I don't understand you at this point. In my approach, `p' is a
> `pointer that represents the address of the storage location where the
> object will be or was located'. More precisely, in your example, `p'
> is a `pointer that represents the address of the storage location
> where the object was located'. At this point in your example,
> Sentence-Y does not apply to `p' because we are not dealing with an
> object destruction. Therefore, it leaves Sentence-A, -B, and -C.
>

I'm asking about your interpretation applied to a comparison between:
(1) In the example in Standard [basic.life]/6 immediately following
Sentence-C, which you discussed earlier in the thread, the
permitted/prohibited uses of pointer "pb" just after "pb->mutate();"
(2) In my example with a union, the permitted/prohibited uses of pointer
"p" just after "p->~std::string();"

I thought you had implied that for case (1), Sentence-Y does not apply, but
Sentences-A, -B, and -C all apply. But maybe I misunderstood, since I'm
having trouble picking quotes that clearly say those things.

>From this last exchange, it does seem in case (2) you say Sentence-Y does
not apply, but Sentences-A, -B, and -C all apply.

Sentence-X contains the phrase "after the lifetime of an object has ended
and before the storage which the object occupied is reused or released".
This describes case (2) since the lifetime of the `std::string` has ended
but its storage has not been reused or released. (The storage will be
released at the end of the compound statement, per the automatic storage
duration rules.) This does not describe case (1) since the point in
question is after the storage has been reused.

Presumably there is some difference in the applicable Standard rules
between case (1) and case (2) because of the condition in Sentence-X. What
would you say those differences are? Or if you disagree with something
above, does it cause a difference between some other pair of situations?

>> > *p; // ok?
> >>
> >> Yes.
>
> Owing to Sentence-B.
>
> --
> Best regards,
> Tadeus
>

Received on 2020-04-19 20:04:26