This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
On Wed, 22 Apr 2009, Gabriel Dos Reis wrote:
> On Wed, Apr 22, 2009 at 5:08 AM, Richard Guenther <rguenther@suse.de> wrote:
> >
> >> I believe there are unclear aspects of ?the reasoning. ?For example,
> >> ?the pointer returned by the allocated as described above meets
> >> the standard semantics, yet is also pointing into the statically
> >> allocated object; no?
> >
> > Yes, so? ?The malloc attribute is a way to prune the points-to set
> > based on language semantics that says that the returned object
> > during its lifetime does not alias with other objects. ?So,
> >
> > char storage[...];
> >
> > T *p = new T();
> > tmp = storage[0];
> >
> > invokes undefined behavior if p points to storage[0].
>
> Where does the C++ standard say that?
3.8/2
"the lifetime of an array object or of an object of type ...
and its lifetime ends when the storage with the array or object
occupies is _reused_ or released" (emphasis mine)
and /1 for when the lifetime of T() starts (which is the point
storage[]s storage is reused).
> >?This is just
> > the same as
> >
> > union { int i; float f; } u;
> >
> > u.i = 1;
> > tmp = u.f;
>
> I'm missing the chapter and verse that says that.
6.5/7 (C standard). int and float are not compatible types.
> > which invokes undefined behavior as well (ok, GCC has a language
> > extension that makes it valid, but it is not a strictly conforming
> > program). ?If you end u.i lifetime by
> >
> > u.f = 0;
> >
> > then you can read from u.f (obviously).
>
> I believe the union case is a completely different case
> (GCC extension notwithstanding).
Maybe. This is the only overlap of C and C++ where C exhibits
a dynamic effective type for an object with a declared type.
Richard.
- References:
- More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)
- Re: More function decorations II (pool_allocator, mt_allocator, debug, stl_list)