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

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-05-04 
09:44:13 UTC ---
(In reply to comment #3)
> > I don't think this is valid as the memory which is done after the operator 
> > new
> is considered as unitialized.
> 
> The code does not use any uninitialized memory.  It does not read the memory. 
> However, it accesses the _type_  and the type exists before an instance of 
> that
> type is made.  

No, it accesses the memory before the constructor begins:

      this_type *new_pt = (this_type *)malloc(total_size);
      new_pt->count = count;

That accesses uninitialized memory before the object's lifetime begins.  And it
accesses it through a pointer of type "this_type*" so will use the offset of
this_type::count, for whatever type this_type is in that scope (which depends
on which of the examples on the stackoverflow page you're claiming is a
compiler bug, in some of them this_type is an alias for A, in others it's a
template parameter instantiated as type B, that's why you need to provide code
here, not vageuly refer to some other site with several code examples.)

> Part of the type information is the layout inside the class. The operator,
> which has been copied into the child via inheritance, 

No, inheritance doesn't mean anything is copied into the child, it means the
function is visible in the scope of the child.

> i.e. the child's version
> of the operator should be seeing the type of the child, not the type of the
> parent.

No, the function "A::operator new" is a member of A and when it uses this_type
it refers to whichever this_type is in scope.  There is no "B::operator new",
there is no child's version ofthe function, it sees the same version i.e.
"A::operator new"

>  The parent is irrelevant once its type is constructed - i.e. after the
> inheritance operation - which occurs before any instances are instantiated.

That's not how C++ works. Inheritance is not an operation.

Reply via email to