[Boost-bugs] [Boost C++ Libraries] #9799: polymorphic_downcast does not support virtual inheritance

Subject: [Boost-bugs] [Boost C++ Libraries] #9799: polymorphic_downcast does not support virtual inheritance
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2014-03-20 16:33:56


#9799: polymorphic_downcast does not support virtual inheritance
------------------------------------------+---------------------------
 Reporter: Camille Gillot <k1000.jlo@…> | Owner: no-maintainer
     Type: Patches | Status: new
Milestone: To Be Determined | Component: utility
  Version: Boost 1.54.0 | Severity: Problem
 Keywords: |
------------------------------------------+---------------------------
 The following code barks at compilation :
 {{{#!cpp
 #include <boost/cast.hpp>

 class A {
 public:
   virtual ~A();
 };

 class B
 : public A
 {};

 class C
 : public virtual A
 {};

 int main() {
   A* b = new B; A* c = new C;
   B* bb = boost::polymorphic_downcast<B*>(b); // Fine
   C* cc = boost::polymorphic_downcast<C*>(c); // Error

   delete b; delete c;
   return 0;
 }
 }}}

 static_cast cannot handle downcast from or through a virtual base class,
 dynamic_cast must be used instead.
 A fix would be to test the case of virtual base class with
 boost::is_virtual_base_of and dispatch the two cases.

 Here is a patch doing it.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/9799>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:15 UTC