More function decorations II (pool_allocator, mt_allocator, debug, stl_list)

Gabriel Dos Reis gdr@integrable-solutions.net
Wed Apr 22 13:00:00 GMT 2009


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?

> 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.

>
> 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).

-- Gaby



More information about the Libstdc++ mailing list