[Bug c++/13005] Pointer wrongly adjusted for derived class containing virtual function

bangerth at dealii dot org gcc-bugzilla@gcc.gnu.org
Tue Nov 11 17:54:00 GMT 2003


------- Additional Comments From bangerth at dealii dot org  2003-11-11 17:54 -------
Just for the record: a simple attempt at showing this like so
--------------------
#include <iostream>

class Derived;
	
struct Base {
    Derived* before;
    Derived* after;
    void insertAfter(Derived* node);
};
	
struct Derived: public Base {
    virtual void foo();
};
	
void Base::insertAfter(Derived* node) {
  this->before->after = node;	// Notice the double indirection.
}


int main ()
{
  Derived node1, node2;
  node2.before = &node1;

  node2.insertAfter (&node2);

  std::cout << node2.before << " " << &node1 << std::endl;
  std::cout << node2.before->after << " " << &node2 << std::endl;
  std::cout << node1.after << " " << &node2 << std::endl;
}

void Derived::foo () 
{}
-----------------------------

doesn't yield anything that's wrong. I get
g/x> /home/bangerth/bin/gcc-3.3.2/bin/c++ x.cc
g/x> ./a.out
0xbffff054 0xbffff054
0xbffff044 0xbffff044
0xbffff044 0xbffff044

I.e. the data seems to get written into the right place. I think you
need to come up with something that shows the problem more clearly.

W.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING


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



More information about the Gcc-bugs mailing list