This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: [Bug libstdc++/29286] [4.0/4.1/4.2/4.3 Regression] placement new does not change the dynamic type as it should
- From: Gabriel Dos Reis <gdr at cs dot tamu dot edu>
- To: gcc-bugzilla at gcc dot gnu dot org
- Cc: gcc-bugs at gcc dot gnu dot org
- Date: 22 May 2007 10:55:36 -0500
- Subject: Re: [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/> <20070522150459.12082.qmail@sourceware.org>
"mark at codesourcery dot com" <gcc-bugzilla@gcc.gnu.org> writes:
| Subject: Re: [4.0/4.1/4.2/4.3 Regression] placement
| new does not change the dynamic type as it should
|
| rguenth at gcc dot gnu dot org wrote:
|
| > - we _cannot_ sink loads across stores.
| >
| > x = *int;
| > *double = 1.0;
| >
| > the store to double may change the dynamic type of what *int
| > points to.
|
| To be clear, you mean something like this, right:
|
| int i;
| int *ip = &i;
| double *dp = (double *)&i;
| int x;
| x = *ip;
| *dp = 1.0;
|
| ?
|
| I think that considering this code valid, and, therefore, forbidding the
| interchange of the last two statements, requires a perverse reading of
| the standard.
I'm not sure Richard is suggesting that -- I believe, we all agree
that the above is invalid. It introduces an assumption that was not
present in Richard's previous message (Richard might want to make
explicit his assumptions). Namely, that we do know the definition of
of the object
int i;
therefore we know that we can not possibly change its dynamic type.
Consider the following instead
// tu-1.C
void f(int* p) {
*p = 90;
// ...
*(double *) p = 8.3748;
};
Is the above code invalid, independent of context? I don't think
you can find a wording in the standard that says it is invalid.
Indeed, consider this:
// tu-2.C
void f(int*);
void g() {
union {
int i;
double d;
} t;
t.i = 42;
f(&t);
cout << t.d << endl;
}
I believe we can all agree the definition of g is valid.
-- Gaby