9
9
// / \brief Templated functions to cast to specific exprt-derived classes
10
10
11
11
#include < typeinfo>
12
+ #include < type_traits>
12
13
#include " invariant.h"
13
14
#include " expr.h"
14
15
@@ -56,12 +57,16 @@ T expr_dynamic_cast(exprt *base)
56
57
// / \brief Cast a pointer to a generic exprt to a specific derived class
57
58
// / \tparam T The pointer or const pointer type to \a TUnderlying to cast to
58
59
// / \tparam TUnderlying An exprt-derived class type
60
+ // / \tparam TExpr The original type to cast from, either exprt or const exprt
59
61
// / \param base Pointer to a generic \ref exprt
60
62
// / \return Pointer to object of type \a TUnderlying
61
63
// / or null if \a base is not an instance of \a TUnderlying
62
64
template <typename T, typename TUnderlying, typename TExpr>
63
65
T expr_dynamic_cast (TExpr *base)
64
66
{
67
+ static_assert (
68
+ std::is_same<typename std::remove_const<TExpr>::type, exprt>::value,
69
+ " Tried to expr_dynamic_cast from something that wasn't an exprt" );
65
70
static_assert (
66
71
std::is_pointer<T>::value,
67
72
" Tried to convert exprt * to non-pointer type" );
@@ -109,12 +114,16 @@ T expr_dynamic_cast(exprt &base)
109
114
// / \brief Cast a reference to a generic exprt to a specific derived class
110
115
// / \tparam T The reference or const reference type to \a TUnderlying to cast to
111
116
// / \tparam TUnderlying An exprt-derived class type
117
+ // / \tparam TExpr The original type to cast from, either exprt or const exprt
112
118
// / \param base Reference to a generic \ref exprt
113
119
// / \return Reference to object of type \a T
114
120
// / \throw std::bad_cast If \a base is not an instance of \a TUnderlying
115
121
template <typename T, typename TUnderlying, typename TExpr>
116
122
T expr_dynamic_cast (TExpr &base)
117
123
{
124
+ static_assert (
125
+ std::is_same<typename std::remove_const<TExpr>::type, exprt>::value,
126
+ " Tried to expr_dynamic_cast from something that wasn't an exprt" );
118
127
static_assert (
119
128
std::is_reference<T>::value,
120
129
" Tried to convert exprt & to non-reference type" );
@@ -133,10 +142,10 @@ inline void validate_operands(
133
142
const exprt &value,
134
143
exprt::operandst::size_type number,
135
144
const char *message,
136
- bool allowMore =false )
145
+ bool allow_more =false )
137
146
{
138
147
DATA_INVARIANT (
139
- allowMore
148
+ allow_more
140
149
? value.operands ().size ()==number
141
150
: value.operands ().size ()>=number,
142
151
message);
0 commit comments