[Bug c++/15054] New: Bad code due to overlapping stack temporaries
uweigand at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Wed Apr 21 19:25:00 GMT 2004
The testcase appended below triggers the abort,
because two temporaries that are concurrently
used get assigned the same stack slot; thus the
constructor of the 'pointer' temporary built
inside the 'element' destructor will clobber
the 'canary' member of the current 'element'.
To reproduce, build the file with -O (both
-O0 and -O2 work correctly).
extern "C" void abort (void);
struct pointer
{
void* ptr;
pointer(void* x = 0) : ptr(x) {}
pointer(const pointer& x) : ptr(x.ptr) {}
};
struct element
{
int canary;
element() : canary(123) { }
~element() { pointer(); if (canary != 123) abort (); }
};
inline pointer
insert(const element& x)
{
return pointer(new element(x));
}
int
main (void)
{
insert(element());
return 0;
}
--
Summary: Bad code due to overlapping stack temporaries
Product: gcc
Version: 3.4.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: uweigand at gcc dot gnu dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC target triplet: s390-ibm-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15054
More information about the Gcc-bugs
mailing list