On Mon, Aug 26, 2013 at 8:17 PM, Jason Merrill <ja...@redhat.com> wrote:
> On 08/26/2013 10:45 AM, Gabriel Dos Reis wrote:
>>
>> Hmm, let's not make it a default.  Replacing global operator new (e.g. for
>> tracing purposes) is a valid C++ programming idiom.
>
>
> Absolutely.  What strikes me as vanishingly unlikely is the idea that the
> replacement operator new would expose pointers to returned memory *and* that
> code would refer to the memory both via one of those pointers and via the
> value of the new-expression in the same function.  That is,
>
> void *last_new_ptr;
> void *operator new (size_t) noexcept(false) {
>   last_new_ptr = ...;
>   return last_new_ptr;
> }
>
> int main()
> {
>   int *a = new int;
>   int *b = (int*)last_new_ptr;
>   *a = 42;
>   *b = 24;
>   if (*a != 24) abort();
> }
>
> I'm happy to let this code break by assuming that the store to b couldn't
> have affected *a.

Amen!

-- Gaby

Reply via email to