This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/29286] [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should
- From: "rguenther at suse dot de" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 24 May 2007 08:03:57 -0000
- Subject: [Bug libstdc++/29286] [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should
- References: <bug-29286-10053@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #153 from rguenther at suse dot de 2007-05-24 09:03 -------
Subject: Re: [4.0/4.1/4.2/4.3 Regression] placement
new does not change the dynamic type as it should
On Thu, 23 May 2007, gdr at cs dot tamu dot edu wrote:
> ------- Comment #151 from gdr at cs dot tamu dot edu 2007-05-24 00:58 -------
> Subject: Re: [4.0/4.1/4.2/4.3 Regression] placement new does not change the
> dynamic type as it should
>
> "rguenther at suse dot de" <gcc-bugzilla@gcc.gnu.org> writes:
>
> [...]
>
> | > Gaby's model says that we know less about dynamic types than we
> | > presently think we do, because there might be a union out there
> | > somewhere. (Fortunately, as Joseph points out, C99 has already answered
> | > this question. Surely we can agree that making C99 and C++ different in
> | > this respect is a bad idea.)
> |
> | I don't think dragging in unions helps us here ;) Maybe Gaby can clarify
> | if and how unions relate here, but I didn't percieve any previous comment
> | as making implicit unions relevant here apart from what GCC and
> | apperantly C99 agree to.
>
> I believe we all agree that placement new changes the dynamic type.
>
>
> I brought in the union example to point of a fundamental problem with
> this issue. I have been following the discussion without saying much,
> until I realized that the interpretation Mark was offering is a
> redefinition of the C++ object model that conflicts with the current
> standard text. That was the point of the union example. In the
> example
>
> void f(int* p, double* q) {
> *p = 42;
> *q = 3.12;
> }
>
> All we know is that after the store to *p, the object there will have
> type int (if it did not already have one). Similarly, for the store
> to *q, the object there will have type double. Can the stores be
> rearranged? Under the current C++ rules (which were inherited from
> C90, and not C99) "yes" if we know that the objects are distinct.
> Can we infer the disjoinctness from the types? "Not always" under
> current C++ rules for union, and in this specific case, the answer is
> "no".
Right, current C++ rules forbid exchanging the stores. But I read it
as it is because the stores may start lifetime of a different
dynamically typed object on the same memory location which p and q
may point to. Whether there is a union "placed" at this memory
location is irrelevant. I read the standard as if the above is
equivalent to
*(new (p) int) = 42;
*(new (q) double) = 3.12;
which as long as we cannot prove that p does not point to the
same memory location as q means that we cannot reorder the stores.
Richard.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29286