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: Mike Stump <mikestump at comcast dot net>
- To: Gabriel Dos Reis <gdr at integrable-solutions dot net>
- Cc: Jan Hubicka <hubicka at ucw dot cz>, Alexander Monakov <amonakov at ispras dot ru>, "gcc-patches at gcc dot gnu dot org" <gcc-patches at gcc dot gnu dot org>, Jason Merrill <jason at redhat dot com>
- Date: Thu, 22 Aug 2013 14:14:26 -0700
- Subject: Re: [C++ patch] Set attributes for C++ runtime library calls
- 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>
On Aug 22, 2013, at 9:45 AM, Gabriel Dos Reis <gdr@integrable-solutions.net> wrote:
>> I.e. can I have something like
>>
>> int a;
>> test()
>> {
>> int *b=new (int);
>> }
>>
>> with custom implementation of new that returns &a?
>
> If the user-supplied operator new returns &a, then it must
> also ensure that 'a' is not used anywhere else -- e.g. I you can't
> do lvalue-to-value conversion on 'a' to see what is written there.
This is wrong, in the c++97 standard there is no such limitation or restriction.
> Because its storage has been reused. That is, aliasing is framed
> in terms of object lifetime and uniqueness of ownership.
Nope, this is wrong. Example:
int i, j;
main() {
i = 1;
j = i;
i = 2;
char *cpi = (char*)&i;
char *cpj = (char*)&j;
for (k= 0; k < sizeof (int); ++k)
cpj[k] = cpi[k];
}
This is well defined. i and j exist, as do the character objects that are pointed to by cpi and cpj. One can use them and interleave them, they can alias, and the character objects are not unique from i and j.