Skip to content

Commit a1a03d6

Browse files
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.
1 parent 98eb5b8 commit a1a03d6

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/IECore/RunTimeTyped.inl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ T *runTimeCast( S *src )
7171
template<typename T, typename S>
7272
boost::intrusive_ptr<T> assertedStaticCast( const boost::intrusive_ptr<S> &src )
7373
{
74-
assert( runTimeCast<T>( src ) );
74+
assert( runTimeCast<T>( src ) == src ); // NOTE : see boost polymorphic_downcast
7575
return boost::static_pointer_cast<T>( src );
7676
}
7777

7878
template<typename T, typename S>
7979
T* assertedStaticCast( S* src )
8080
{
81-
assert( runTimeCast<T>( src ) );
81+
assert( runTimeCast<T>( src ) == src ); // NOTE : see boost polymorphic_downcast
8282
return static_cast<T *>( src );
8383
}
8484

0 commit comments

Comments
 (0)