[aspectc-user] gcc 2.96 vs. ResultBuffer

Timothy Stack stack at cs.utah.edu
Tue Mar 13 06:12:41 CET 2007


I seem to be having some trouble with garbage return values when  
using gcc 2.96.  My test case is a simple method that returns an  
integer and has one advice applied to it.  When I run it, the return  
value of the method (always 1), will come out garbled.  As best as I  
can figure, it's due to the memory layout of the ResultBuffer  
structure.  I'll copy the generated code here for reference:

   struct AnyResultBuffer {};
   template <typename T> struct ResultBuffer : public AnyResultBuffer {
     char _data[sizeof (T)];
     ~ResultBuffer () { ((T*)_data)->T::~T(); }
     operator T& () const { return *(T*)_data; }

In gcc 2.96, it looks like the ResultBuffer's _data member is located  
one byte after the base pointer (probably because the parent struct  
is one byte in size).  So, the following placement new when the  
method is called, doesn't quite work (I think):

   ::new (&result) int (...);

In later gcc's, the sizeof AnyResultBuffer is still one, but it does  
not offset the _data member by a byte, like in 2.96.  So, the test  
works fine.

Perhaps I'm missing something, but I would think you'd want the  
placement new to refer to the _data member directly...


tim stack

More information about the aspectc-user mailing list