This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/11915] Aliasing problems with user-defined operator new


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11915


reichelt at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
            Summary|use of option -frename-     |Aliasing problems with user-
                   |registers lead to wrong     |defined operator new
                   |behaviour                   |


------- Additional Comments From reichelt at gcc dot gnu dot org  2003-08-15 18:41 -------
Here's a reduced testcase.

It returns 1 when compiled with "g++ -O2" and
0 when compiled with "g++ -O2 -fno-strict-aliasing":

================================================
char Pool[32];

struct A { A* next; };
A* a=0;

struct B
{
    void* p;
    B() : p((void*)4711) {}

    void* operator new(unsigned)
    {
        if (!a) a = (A*)Pool;
        A* q = a;
        a = a->next;
        return q;
    }
};

int main ()
{
    new B;
    return a == (void*)4711;
}
================================================

I'm not sure whether this example violates aliasing rules,
but it's an aliasing problem nevertheless. I updated the
summary accordingly.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]