From a1a03d6555892e12d4d9f789e4390793d16601b4 Mon Sep 17 00:00:00 2001 From: proberts Date: Thu, 16 Feb 2023 19:21:16 +0000 Subject: [PATCH] RunTimeTyped : IECore::assertedStaticCast allow null source pointer * use approach taken by boost polymorphic_downcast and compare source pointer to casted pointer, this has added benefit of not compiling if Target type cannot be converted to Source type so should detect programming errors at compile time. --- include/IECore/RunTimeTyped.inl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/IECore/RunTimeTyped.inl b/include/IECore/RunTimeTyped.inl index 584942bbd4..4a01bf8f37 100644 --- a/include/IECore/RunTimeTyped.inl +++ b/include/IECore/RunTimeTyped.inl @@ -71,14 +71,14 @@ T *runTimeCast( S *src ) template boost::intrusive_ptr assertedStaticCast( const boost::intrusive_ptr &src ) { - assert( runTimeCast( src ) ); + assert( runTimeCast( src ) == src ); // NOTE : see boost polymorphic_downcast return boost::static_pointer_cast( src ); } template T* assertedStaticCast( S* src ) { - assert( runTimeCast( src ) ); + assert( runTimeCast( src ) == src ); // NOTE : see boost polymorphic_downcast return static_cast( src ); }