C++ Logo

STD-DISCUSSION

Advanced search

Subject: Re: About the description of [basic.life]/6
From: Andrew Schepler (aschepler_at_[hidden])
Date: 2020-04-18 15:55:21


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.

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"? Then what are those limited
ways it may be used, or the limitations on its use? Does any other clause
in the Standard elaborate that case, if the following sentences and
paragraphs don't?

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");
    p->~std::string();
    // The lifetime of the object p pointed at has ended, but its storage
has not been reused or released.
    // At this point, how can p be used and how may it not be used?
    *p; // ok?
}

On Sat, Apr 18, 2020 at 4:26 PM Tadeus Prastowo <tadeus.prastowo_at_[hidden]>
wrote:

> On Sat, Apr 18, 2020 at 10:19 PM Andrew Schepler <aschepler_at_[hidden]>
> wrote:
> >
> > > If my approach is taken, I think everything already falls in place
> properly and a DR is not needed.
> >
> > I'm not sure if I understand what you've said. I think you've concluded
> that paragraph 6 applies to pb and paragraph 7 applies to *pb despite the
> fact that the storage has been reused.
>
> Yes, that's right.
>
> > Is that because the phrase "such a pointer" refers to the noun phrase
> "any pointer that represents the address of the storage location where the
> object will be or was located", but without the preceding qualifications of
> "Before ... or, after ... released"?
>
> Yes, that's right.
>
> > I think that would be a strange reading, for a few reasons. Or is it
> something else?
>
> No, it is not something else. I think you already understand my approach.
>
> --
> Best regards,
> Tadeus
>



STD-DISCUSSION list run by std-discussion-owner@lists.isocpp.org

Older Archives on Google Groups