This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ object model and dynamic type


Michael Matz <matz@suse.de> writes:

[...]

|  Â Âint g() {
|  Â Â Â int i = 3;
|  Â Â Â int* p = &i;
|        new (p) float (1.2);

In the abstract model, this would be invalid.

|        useme((float*)p);
|        new (p) int (42);
|  Â Â Â return i;
|  Â Â}
| 
| Note how p8 (even without the dtor restriction) doesn't render this 
| program invalid (at scope exit the storage in question holds an object of 
| the declared type). 

agreed.

| p7 also doesn't render this invalid: while the 
| storage holds a float we don't refer to it via the original name, we have 
| no reference, and we use a pointer to a different object, not the original 
| pointer (assume that useme() only accesses this as float).  And when we 
| use the original name 'i' later the storage indeed fulfills the 
| requirements of p7 again.
| 
| It would be good to clarify if it's intended that such program be valid, 
| or if also such intermediate reuse of storage (with proper restoring of 
| declared types) is intended to be invalid.

I'll pass these comments on, and make sure that th wording reflects the
abstract model.

-- Gaby


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]