This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Is this a bug? Dynamic cast error similar to thunk error.



During my futile attempts to work around the very frustrating bug
in the vtable-thunk code I stumbled across the following code:

// Example derived from Alexandre Oliva's testsuite code.
#include <cstdlib>
#include <cstdio>
using namespace std;
struct vbase
{
  virtual int get_a() const = 0;
};
struct base: virtual vbase
{
 int a;
        
 base (int aa) : a(aa) { }
 int get_a() const { return a; }        
 static int get_aa (vbase *v) {
   base *b = dynamic_cast<base*>(v);
   return b->a;
 }
 static int get_aaa (base *b) {
   return b->a;
 }        
};
struct mid: base
{
  mid (int bb) : base(bb) {
    printf ("get_a=%d\n", ((vbase*)this)->get_a());
    printf ("get_aa=%d\n", base::get_aa (this));
    printf ("get_aaa=%d\n", base::get_aaa (this));
  }        
};
struct derived: virtual mid
{
  derived (int cc) : mid (cc) {}
};
int main ()
{
  derived dd (42);
}

-------------------------------
If compiled with g++ 2.95.1 and -fvtable-thunks the output is as
follows:
get_a=-1073743408
get_aa=-1073743408
get_aaa=42

When recompiled with -fno-vtable-thunks the output is as follows:
get_a=42
get_aa=-1073743408
get_aaa=42

get_aa is still very wrong!!!!!! Interestingly get_a and get_aa 
have the same wrong value. Now is this because I am doing something
illegal according to C++ standards? The compiler emits no warnings.

Regards
Fredrik Ohrstrom 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]