@@ -125,30 +125,31 @@ optionalt<Target> numeric_cast(const exprt &arg)
125
125
}
126
126
127
127
// / Convert an mp_integer to integral type Target
128
- // / An invariant with fail with message "Bad conversion" if conversion
129
- // / is not possible.
128
+ // / An invariant with fail if the conversion is not possible.
130
129
// / \tparam Target: type to convert to
131
130
// / \param arg: mp_integer
132
131
// / \return value of type Target
133
132
template <typename Target>
134
133
Target numeric_cast_v (const mp_integer &arg)
135
134
{
136
135
const auto maybe = numeric_castt<Target>{}(arg);
137
- INVARIANT (maybe, " Bad conversion " );
136
+ INVARIANT (maybe, " mp_integer should be convertible to target integral type " );
138
137
return *maybe;
139
138
}
140
139
141
140
// / Convert an expression to integral type Target
142
- // / An invariant with fail with message "Bad conversion" if conversion
143
- // / is not possible.
141
+ // / An invariant with fail if the conversion is not possible.
144
142
// / \tparam Target: type to convert to
145
143
// / \param arg: constant expression
146
144
// / \return value of type Target
147
145
template <typename Target>
148
146
Target numeric_cast_v (const exprt &arg)
149
147
{
150
148
const auto maybe = numeric_castt<Target>{}(arg);
151
- INVARIANT (maybe, " Bad conversion" );
149
+ INVARIANT_WITH_DIAGNOSTICS (
150
+ maybe,
151
+ " expression should be convertible to target integral type" ,
152
+ irep_pretty_diagnosticst (arg));
152
153
return *maybe;
153
154
}
154
155
0 commit comments