Date: Fri, 11 Sep 2020 09:56:18 +0800
The standard rule does not say that, so `ri` does not gurant to refer to
the new subobject, because the rule only says:
>a new object is created at the storage location which the original object
occupied, a pointer that pointed to the original object, a reference that
referred to the original object, or the name of the original object will
automatically refer to the new object.
please note the wording `new object` and `original object`. In your
example, you created a new object of type `S` while you possess a reference
that referred to the subobject of the original object. which violate these
rules:
>the storage that o2 occupies exactly overlays the storage that o1occupied,
and.
>o1 and o2 are of the same type (ignoring the top-level cv-qualifiers)
So, anyhow, Your example is not covered by these rules.
<language.lawyer_at_[hidden]> 于2020年9月10日周四 下午6:30写道:
> I think, p1 p2 must be the old and the new objects, they can't be the same
> object.
> I assume p1 and p2 are needed for the following code:
>
> struct S { int i; };
>
> S s {};
> int& ri = s.i;
>
> new (&s) S {};
>
>
> where the wording guarantees that `ri` will refer to the new int subobject
> (o2) of the object of type S (p2)
>
>
> On 10/09/2020 12:43, jim x via Std-Discussion wrote:
> > I think your first opinion is the intent of the rule. Because, according
> > to the rule [intro.object#2] <https://eel.is/c++draft/intro.object#2>,
> the
> > new object has became the subobject of the object X, and the condition
> "o1
> > and o2 are direct subobjects of objects P1 and P2" is true. The standard
> > does not say `P1` and `P2` shall not be the same object, the object
> > `X` itself satisfies all rules listed in [basic.life#8]
> > <https://eel.is/c++draft/basic.life#8>. So, there's no necessary to use
> > `std::launder`.
> >
> > John Mousseau via Std-Discussion <std-discussion_at_[hidden]>
> > 于2020年9月9日周三 上午1:49写道:
> >
> >> Dear list members,
> >>
> >> in draft N4860 <https://isocpp.org/files/papers/N4860.pdf>, which I
> >> assume is close to C++20, the wording of [basic.life]/8 differs from
> C++17
> >> in that the notion of "transparently replaceable" was involved. I am
> >> wondering whether condition 8.5 of that paragraph allows for p1 and p2
> to
> >> be the same object.
> >>
> >> Consider the following most trivial example:
> >>
> >> struct X {int i; float f;};
> >> X x{3, 3.f};
> >> new(&x.i) int(5);
> >> // x.i == 5 without launder? True in C++17.
> >>
> >> According to C++17's wording this is surely the case as there is no
> >> const-qualification involved at all. However, in the newest wording,
> while
> >> conditions (8.1) through (8.4) are fulfilled (for o1 and o2 being the
> old
> >> and new int respectively), condition (8.5) might be unfulfilled, as
> neither
> >> are both objects complete, nor are they subobjects of (different)
> objects
> >> p1 and p2, unless, by [intro.object]/2, the new int becomes a subobject
> of
> >> x, and when then consider p1 and p2 of [basic.life]/8.5 to be
> identical. If
> >> we then consider x to be transparently-replaceable by itself, the
> condition
> >> would be fulfilled. Is that the intended interpretation or is the
> intention
> >> that the access in my example now requires std::launder even though no
> >> constness is involved?
> >>
> >> Sorry in case I am not seeing the obvious and thank you for your time.
> >>
> >> Best Regards
> >> John Mousseau
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> >>
> >
> >
>
the new subobject, because the rule only says:
>a new object is created at the storage location which the original object
occupied, a pointer that pointed to the original object, a reference that
referred to the original object, or the name of the original object will
automatically refer to the new object.
please note the wording `new object` and `original object`. In your
example, you created a new object of type `S` while you possess a reference
that referred to the subobject of the original object. which violate these
rules:
>the storage that o2 occupies exactly overlays the storage that o1occupied,
and.
>o1 and o2 are of the same type (ignoring the top-level cv-qualifiers)
So, anyhow, Your example is not covered by these rules.
<language.lawyer_at_[hidden]> 于2020年9月10日周四 下午6:30写道:
> I think, p1 p2 must be the old and the new objects, they can't be the same
> object.
> I assume p1 and p2 are needed for the following code:
>
> struct S { int i; };
>
> S s {};
> int& ri = s.i;
>
> new (&s) S {};
>
>
> where the wording guarantees that `ri` will refer to the new int subobject
> (o2) of the object of type S (p2)
>
>
> On 10/09/2020 12:43, jim x via Std-Discussion wrote:
> > I think your first opinion is the intent of the rule. Because, according
> > to the rule [intro.object#2] <https://eel.is/c++draft/intro.object#2>,
> the
> > new object has became the subobject of the object X, and the condition
> "o1
> > and o2 are direct subobjects of objects P1 and P2" is true. The standard
> > does not say `P1` and `P2` shall not be the same object, the object
> > `X` itself satisfies all rules listed in [basic.life#8]
> > <https://eel.is/c++draft/basic.life#8>. So, there's no necessary to use
> > `std::launder`.
> >
> > John Mousseau via Std-Discussion <std-discussion_at_[hidden]>
> > 于2020年9月9日周三 上午1:49写道:
> >
> >> Dear list members,
> >>
> >> in draft N4860 <https://isocpp.org/files/papers/N4860.pdf>, which I
> >> assume is close to C++20, the wording of [basic.life]/8 differs from
> C++17
> >> in that the notion of "transparently replaceable" was involved. I am
> >> wondering whether condition 8.5 of that paragraph allows for p1 and p2
> to
> >> be the same object.
> >>
> >> Consider the following most trivial example:
> >>
> >> struct X {int i; float f;};
> >> X x{3, 3.f};
> >> new(&x.i) int(5);
> >> // x.i == 5 without launder? True in C++17.
> >>
> >> According to C++17's wording this is surely the case as there is no
> >> const-qualification involved at all. However, in the newest wording,
> while
> >> conditions (8.1) through (8.4) are fulfilled (for o1 and o2 being the
> old
> >> and new int respectively), condition (8.5) might be unfulfilled, as
> neither
> >> are both objects complete, nor are they subobjects of (different)
> objects
> >> p1 and p2, unless, by [intro.object]/2, the new int becomes a subobject
> of
> >> x, and when then consider p1 and p2 of [basic.life]/8.5 to be
> identical. If
> >> we then consider x to be transparently-replaceable by itself, the
> condition
> >> would be fulfilled. Is that the intended interpretation or is the
> intention
> >> that the access in my example now requires std::launder even though no
> >> constness is involved?
> >>
> >> Sorry in case I am not seeing the obvious and thank you for your time.
> >>
> >> Best Regards
> >> John Mousseau
> >> --
> >> Std-Discussion mailing list
> >> Std-Discussion_at_[hidden]
> >> https://lists.isocpp.org/mailman/listinfo.cgi/std-discussion
> >>
> >
> >
>
Received on 2020-09-10 21:00:05