"mark at codesourcery dot com" <[EMAIL PROTECTED]> 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