[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#395837: marked as done (g++-4.1: dynamic_cast returns different results based on the order of bases)



Your message dated Sun, 11 Apr 2010 14:30:35 +0000
with message-id <E1O0yBH-00006w-SG@ravel.debian.org>
and subject line C++ and mudflap packages not built anymore from the gcc-4.1 source
has caused the Debian Bug report #395837,
regarding g++-4.1: dynamic_cast returns different results based on the order of bases
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact owner@bugs.debian.org
immediately.)


-- 
395837: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=395837
Debian Bug Tracking System
Contact owner@bugs.debian.org with problems
--- Begin Message ---
Package:g++-4.1
Version:4.1.1-18

What should dynamic_cast return if we have virtual base class that is
first derived publicly, then privately? The following example shows
that in gcc-4.1 dynamic_cast result depends on the order of
declarations:
/////// cl1.cc //////////////
#include <iostream>
using namespace std;
class A {
public:
 virtual ~A() {}
};

class B : public virtual A {};
class C : private virtual A {}; //! derived privately
class T { public: virtual ~T() {}};
class D : public C, public B, public T {};

A* f(T* p) {return dynamic_cast<A*>(p);}

int main() {
 D* p = new D;
 A* q = p;
 cout << f(p) << " " << q << endl;
}
////////// end of cl1.cc /////////

g++ cl1.cc && ./a.out
0x804b008 0x804b008
^^^^^^^^^
dynamic_cast from T* to A* is successfull


Now, derive D first from B then C:

////////////////////// cl2.cc /////////////////
#include <iostream>
using namespace std;
class A {
public:
 virtual ~A() {}
};

class B : public virtual A {};
class C : private virtual A {};
class T {
public:
   virtual ~T() {}
};
class D : public B, public C, public T {}; //! change order of B and C


A* f(T* p) {return dynamic_cast<A*>(p);}

int main() {
 D* p = new D;
 A* q = p;
 cout << f(p) << " " << q << endl;
}
///////////////// end of cl2.cc /////////////

g++ cl2.cc && ./a.out
0 0x804b008
^^
dynamic_cast from T* to A* failed.

On the other hand paragraph 5.2.7.8 of the C++ standard seems to
indicate that dynamic_cast should succeed  (T* is public base; is A
unambiguous? -- yes, is A public base - yes (and no?))
Same results with gcc-snapshot.

Vladimir




g++ -v :
Using built-in specs.
Target: i486-linux-gnu
Configured with: ../src/configure -v
--enable-languages=c,c++,fortran,objc,obj-c++,treelang --prefix=/usr
--enable-shared --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix --enable-nls
--program-suffix=-4.1 --enable-__cxa_atexit --enable-clocale=gnu
--enable-libstdcxx-debug --enable-mpfr --with-tune=i686
--enable-checking=release i486-linux-gnu
Thread model: posix
gcc version 4.1.2 20061026 (prerelease) (Debian 4.1.1-18)


--- End Message ---
--- Begin Message ---
The C++ and mudflap binary packages are not built anymore from the
gcc-4.1 source package.  Tagging this report as won't fix, and closing
the report.

Please check if the problem is fixed in gcc-4.4 (or gcc-4.5/gcc-snapshot).
If the problem is not fixed, and not yet reported for the new compiler
version(s), open a new report.


--- End Message ---

Reply to: