Skip to content

Commit f978fa1

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 c4d5cac commit f978fa1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

include/IECore/RunTimeTyped.inl

+2-2
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)