Skip to content

Commit d35710f

Browse files
NathanJPhillipssmowton
authored andcommitted
Made validate_expr non-template
1 parent de8a8d0 commit d35710f

File tree

2 files changed

+65
-93
lines changed

2 files changed

+65
-93
lines changed

src/util/expr_cast.h

+14-14
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,16 @@
1313
#include "expr.h"
1414

1515

16-
/// \brief Check whether a reference to a generic \ref exprt is of a specific derived class
16+
/// \brief Check whether a reference to a generic \ref exprt is of a specific
17+
/// derived class.
18+
///
1719
/// Implement template specializations of this function to enable casting
20+
///
1821
/// \tparam T The exprt-derived class to check for
1922
/// \param base Reference to a generic \ref exprt
2023
/// \return true if \a base is of type \a T
2124
template<typename T> bool check_expr_type(const exprt &base);
2225

23-
/// \brief Check whether a reference to a generic \ref exprt is of a specific derived class
24-
/// Implement template specializations of this function to enable casting
25-
/// \tparam T The exprt-derived class to check for
26-
/// \param base Reference to a generic \ref exprt
27-
/// \return true if \a base is of type \a T
28-
template<typename T> void validate_expr(const T &value) { }
29-
3026
template<typename T> struct remove_constt;
3127
template<typename T> struct remove_constt<const T> { using type=T; };
3228
template<typename T> struct ptr_typet;
@@ -35,10 +31,12 @@ template<typename T> struct ref_typet;
3531
template<typename T> struct ref_typet<T &> { using type=T; };
3632

3733

38-
/// \brief Cast a constant pointer to a generic exprt to a specific derived class
34+
/// \brief Cast a constant pointer to a generic exprt to a specific derived
35+
/// class
3936
/// \tparam T The exprt-derived class to cast to
4037
/// \param base Pointer to a generic \ref exprt
41-
/// \return Pointer to object of type \a T or null if \a base is not an instance of \a T
38+
/// \return Pointer to object of type \a T or null if \a base is not an
39+
/// instance of \a T
4240
template<typename T>
4341
T expr_dynamic_cast(const exprt *base)
4442
{
@@ -51,7 +49,8 @@ T expr_dynamic_cast(const exprt *base)
5149
/// \brief Cast a pointer to a generic exprt to a specific derived class
5250
/// \tparam T The exprt-derived class to cast to
5351
/// \param base Pointer to a generic \ref exprt
54-
/// \return Pointer to object of type \a T or null if \a base is not an instance of \a T
52+
/// \return Pointer to object of type \a T or null if \a base is not an
53+
/// instance of \a T
5554
template<typename T>
5655
T expr_dynamic_cast(exprt *base)
5756
{
@@ -75,11 +74,12 @@ T expr_dynamic_cast(TExpr *base)
7574
if(!check_expr_type<TUnderlying>(*base))
7675
return nullptr;
7776
T value=static_cast<T>(base);
78-
validate_expr<TUnderlying>(*value);
77+
validate_expr(*value);
7978
return value;
8079
}
8180

82-
/// \brief Cast a constant reference to a generic exprt to a specific derived class
81+
/// \brief Cast a constant reference to a generic exprt to a specific derived
82+
/// class
8383
/// \tparam T The exprt-derived class to cast to
8484
/// \param base Reference to a generic \ref exprt
8585
/// \return Reference to object of type \a T
@@ -119,7 +119,7 @@ T expr_dynamic_cast(TExpr &base)
119119
if(!check_expr_type<TUnderlying>(base))
120120
throw std::bad_cast();
121121
T value=static_cast<T>(base);
122-
validate_expr<TUnderlying>(value);
122+
validate_expr(value);
123123
return value;
124124
}
125125

0 commit comments

Comments
 (0)