[bug] Visual Studio 2003 versus polymorphic_downcast

Visual studio 2003 seems to be buggy in a way that can break boost::polymorphic_downcast. Unless I am missing something, it's a rather scary silent failure: ### # include <cassert> class left {}; class right {}; class derived : public left, public right {}; int _tmain(int argc, _TCHAR* argv[]) { derived x; const derived *xp=&x; right *yp=&x; // assert(const_cast<derived*>(xp)==yp); no bug assert(xp==yp); //bug: this fires return 0; } ### This bug causes the assert in polymorphic_downcast to fire when it shouldn't. Here is one possible patched version: template <class Target, class Source> inline Target polymorphic_downcast(Source* x BOOST_EXPLICIT_DEFAULT_TARGET) { #if BOOST_WORKAROUND(BOOST_MSVC, <= 1310) assert( static_cast<const Source*>(dynamic_cast<Target>(x)) == x ); // detect logic error #else assert( dynamic_cast<Target>(x) == x ); // detect logic error #endif return static_cast<Target>(x); } ### The problem is not present in VS 2005. Thoughts? Mat
participants (1)
-
Mat Marcus