This is the mail archive of the gdb-prs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/2416: casting to reference type causes internal error


>Number:         2416
>Category:       c++
>Synopsis:       casting to reference type causes internal error
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 27 17:58:01 UTC 2008
>Closed-Date:
>Last-Modified:
>Originator:     aristovski@qnx.com
>Release:        6.7
>Organization:
>Environment:
linux
>Description:
When casting to a reference type, gdb_assert is triggered causing internal error.
>How-To-Repeat:
Use the following to create files main.cc and init

=== main.cc ===
#include <cstdlib>
#include <iostream>
using namespace std;

namespace IP {
  class base {
  public:
    base () {
    cout << "Base class\n";
    }
    virtual void foo() {}
  };

  class derived: public base {
    public:
      derived () {
      cout << "Derived class\n";
      derivedfield = 42;
    }
    void foo() {
      cout << "derived::foo" << endl;
    }
    int derivedfield;
  };
}

void testCast1 (IP::base & arg) {
  cout << "Test the casting\n";
  arg.foo();
}

void testCast2 (IP::base (&arr)[2])
{
  arr[0].foo();
  arr[1].foo();
}

void testCast3 (IP::base *(&arr)[2])
{
  arr[0]->foo();
  arr[1]->foo();
}

int main(int argc, char *argv[]) {
  IP::base a[] = { IP::derived(), IP::base() };
  IP::base *d = new IP::derived();
  IP::base * basder[] = { new IP::derived(), new IP::base() };
  testCast1(*d);
  testCast2(a);
  testCast3(basder);
  return 1;
}
================

=== file init ===
file main
b testCast1
b testCast2
b testCast3

r

print ('IP::derived' &) arg
echo "I'm still alive..."
c
=================

now compile main.cc:
g++ -g -o main main.cc

Finally, run
gdb -x init
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


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