C++ Logo

std-discussion

Advanced search

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

From: Tadeus Prastowo <tadeus.prastowo_at_[hidden]>
Date: Mon, 20 Apr 2020 01:18:21 +0200
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.

>> > 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();'.

>> > 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.

>> > *p; // ok?
>>
>> Yes.

Owing to Sentence-B.

-- 
Best regards,
Tadeus

Received on 2020-04-19 18:21:32