This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [C++ patch] Set attributes for C++ runtime library calls
- From: Jason Merrill <jason at redhat dot com>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>, Jan Hubicka <hubicka at ucw dot cz>
- Cc: Alexander Monakov <amonakov at ispras dot ru>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 26 Aug 2013 21:17:43 -0400
- Subject: Re: [C++ patch] Set attributes for C++ runtime library calls
- Authentication-results: sourceware.org; auth=none
- References: <20130822131927 dot GA18084 at kam dot mff dot cuni dot cz> <CAAiZkiDRZj-Fzy2+zUo9Z2B5ShvJ6K_duNyX1SKfrEZeX1NNZQ at mail dot gmail dot com> <alpine dot LNX dot 2 dot 00 dot 1308221836460 dot 30125 at monopod dot intra dot ispras dot ru> <20130822152111 dot GB19256 at kam dot mff dot cuni dot cz> <CAAiZkiA5wyTn0A_eMZ8d-crnq0KY0ut6R1ffh+2xsTp51dkWEg at mail dot gmail dot com> <20130822153958 dot GE19256 at kam dot mff dot cuni dot cz> <CAAiZkiCWf43bVyuVJC+D1=ghSLGTXsi5FbWVdUwX1kq4cNvavg at mail dot gmail dot com> <20130822161644 dot GC24022 at kam dot mff dot cuni dot cz> <CAAiZkiC7tztfKcwET95cacX52=xdRf+QuuUEUfOXTF+9QD69DA at mail dot gmail dot com> <521B6116 dot 4050309 at redhat dot com> <20130826143820 dot GB19397 at atrey dot karlin dot mff dot cuni dot cz> <CAAiZkiDgWGY6YRhODJ0copoOhcGCy6AfWpBLQsaHLN1rY2R22g at mail dot gmail dot com>
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.
Jason