This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/11915] Aliasing problems with user-defined operator new
- From: "reichelt at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 15 Aug 2003 18:41:16 -0000
- Subject: [Bug c++/11915] Aliasing problems with user-defined operator new
- References: <20030814074726.11915.Andreas.Glowatz@philips.com>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
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.