@@ -88,6 +88,8 @@ T expr_dynamic_cast(TExpr *base)
8888// / \param base Reference to a generic \ref exprt
8989// / \return Reference to object of type \a T
9090// / \throw std::bad_cast If \a base is not an instance of \a T
91+ // / \remark If CBMC assertions (PRECONDITION) are set to abort then this will
92+ // / abort rather than throw if \a base is not an instance of \a T
9193template <typename T>
9294T expr_dynamic_cast (const exprt &base)
9395{
@@ -102,6 +104,8 @@ T expr_dynamic_cast(const exprt &base)
102104// / \param base Reference to a generic \ref exprt
103105// / \return Reference to object of type \a T
104106// / \throw std::bad_cast If \a base is not an instance of \a T
107+ // / \remark If CBMC assertions (PRECONDITION) are set to abort then this will
108+ // / abort rather than throw if \a base is not an instance of \a T
105109template <typename T>
106110T expr_dynamic_cast (exprt &base)
107111{
@@ -118,6 +122,8 @@ T expr_dynamic_cast(exprt &base)
118122// / \param base Reference to a generic \ref exprt
119123// / \return Reference to object of type \a T
120124// / \throw std::bad_cast If \a base is not an instance of \a TUnderlying
125+ // / \remark If CBMC assertions (PRECONDITION) are set to abort then this will
126+ // / abort rather than throw if \a base is not an instance of \a TUnderlying
121127template <typename T, typename TUnderlying, typename TExpr>
122128T expr_dynamic_cast (TExpr &base)
123129{
@@ -130,6 +136,7 @@ T expr_dynamic_cast(TExpr &base)
130136 static_assert (
131137 std::is_base_of<exprt, TUnderlying>::value,
132138 " The template argument T must be derived from exprt." );
139+ PRECONDITION (can_cast_expr<TUnderlying>(base));
133140 if (!can_cast_expr<TUnderlying>(base))
134141 throw std::bad_cast ();
135142 T value=static_cast <T>(base);
0 commit comments