@@ -88,6 +88,8 @@ T expr_dynamic_cast(TExpr *base)
88
88
// / \param base Reference to a generic \ref exprt
89
89
// / \return Reference to object of type \a T
90
90
// / \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
91
93
template <typename T>
92
94
T expr_dynamic_cast (const exprt &base)
93
95
{
@@ -102,6 +104,8 @@ T expr_dynamic_cast(const exprt &base)
102
104
// / \param base Reference to a generic \ref exprt
103
105
// / \return Reference to object of type \a T
104
106
// / \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
105
109
template <typename T>
106
110
T expr_dynamic_cast (exprt &base)
107
111
{
@@ -118,6 +122,8 @@ T expr_dynamic_cast(exprt &base)
118
122
// / \param base Reference to a generic \ref exprt
119
123
// / \return Reference to object of type \a T
120
124
// / \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
121
127
template <typename T, typename TUnderlying, typename TExpr>
122
128
T expr_dynamic_cast (TExpr &base)
123
129
{
@@ -130,6 +136,7 @@ T expr_dynamic_cast(TExpr &base)
130
136
static_assert (
131
137
std::is_base_of<exprt, TUnderlying>::value,
132
138
" The template argument T must be derived from exprt." );
139
+ PRECONDITION (can_cast_expr<TUnderlying>(base));
133
140
if (!can_cast_expr<TUnderlying>(base))
134
141
throw std::bad_cast ();
135
142
T value=static_cast <T>(base);
0 commit comments