C++ Logo


Advanced search

Subject: Re: About the description of [basic.life]/6
From: Andrew Schepler (aschepler_at_[hidden])
Date: 2020-04-17 17:02:23

That seems mostly right, but a few things still sounded off to me. So I'm
not sure if I'm agreeing or disagreeing, reading something a way it wasn't
met, etc., but:

Recapping the labels from previous messages:

"Before the lifetime of an object has started but after the storage which
the object will occupy has been allocated or, after the lifetime of an
object has ended and before the storage which the object occupied is reused
or released, any pointer"
    "that represents the address of the storage location where the object
will be or was located"
"may be used but only in limited ways."

    "For an object under construction or destruction,"
"see [class.cdtor]."

"Otherwise, such a pointer"
    (Condition-3 ?):
    "refers to allocated storage ([basic.stc.dynamic.allocation]),"
"and using the pointer as if the pointer were of type void* is

"Indirection through such a pointer is permitted but the resulting lvalue
may only be used in limited ways, as described below."

"The program has undefined behavior if:" ... [through paragraph (6.5)]

I would say Sentence-X is the topic sentence for all of paragraph 6,
including the list (6.1)-(6.5). None of this applies to pointers that do
not satisfy Condition-1 (like a pointer to an object during its lifetime, a
pointer with null pointer value, or a pointer with indeterminate value).
For a pointer to an object satisfying Condition-2 (yes, a special case of
pointers satisfying Condition-1), [class.cdtor] covers all limitations on
uses of the pointer. The word "Otherwise" contrasts with Condition-2, so
that Sentences A, B, and C all apply to pointers which satisfy Condition-1
but not Condition-2. In Sentence-A, "refers to allocated storage" is not a
new condition, just a rephrasing or description of Condition-1, with a
better term to use since we don't want to say "pointer to object" when no
object exists.

So for a pointer P which satisfies Condition-1 and Condition-2:
 - The rules of [class.cdtor] apply. Sentence-A, Sentence-B, and Sentence-C
do not apply.
And for a pointer P which satisfies Condition-1 but not Condition-2:
 - Per Sentence-A, it can be used "as if it were of type void*". (This is
somewhat vague, and might be just descriptive of what's NOT ruled out by
paragraph 7 and sentence C.)
 - Per Sentence-B, *P and P->m are valid as long as the rules in paragraph
7 which apply to that lvalue are met.
 - Per Sentence-C, certain uses have undefined behavior.

And it's worth noting I'm pretty sure the rules of [class.cdtor] are always
at least as permissive as the rules from paragraph 7 and Sentence-C:
anything permitted for a pointer to allocated storage without an object
under construction or destruction is also allowed for a pointer to an
object under construction or destruction.

-- Andrew Schepler

On Fri, Apr 17, 2020 at 1:42 PM Tadeus Prastowo via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> On Fri, Apr 17, 2020 at 6:04 AM yo mizu via Std-Discussion
> <std-discussion_at_[hidden]> wrote:
> >
> > I am glad to inform you that my question is now solved.
> That's great!
> > Thank you very much!
> My pleasure.
> > --
> > Best regards,
> > Yo Mizu
> --
> Best regards,
> Tadeus
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

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

Older Archives on Google Groups