From a1229692b06bd659a2485ff1ff4ea73654dab1f7 Mon Sep 17 00:00:00 2001 From: Soonho Kong Date: Thu, 8 Aug 2013 16:12:27 -0700 Subject: [PATCH] Add static_asserts for higher-order functions in kernel/for_each.h and kernel/pp.cpp --- src/kernel/for_each.h | 4 +++- src/kernel/pp.cpp | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/kernel/for_each.h b/src/kernel/for_each.h index f828fd96c..cc24b88c5 100644 --- a/src/kernel/for_each.h +++ b/src/kernel/for_each.h @@ -13,6 +13,8 @@ template class for_each_fn { expr_cell_offset_set m_visited; F m_f; + static_assert(std::is_same::type, void>::value, + "for_each_fn: return type of m_f is not void"); void apply(expr const & e, unsigned offset) { if (is_shared(e)) { @@ -22,7 +24,7 @@ class for_each_fn { m_visited.insert(p); } - m_f(e, offset); + m_f(e, offset); switch (e.kind()) { case expr_kind::Constant: case expr_kind::Type: case expr_kind::Value: case expr_kind::Var: diff --git a/src/kernel/pp.cpp b/src/kernel/pp.cpp index 3aa234c8b..bd5f47a04 100644 --- a/src/kernel/pp.cpp +++ b/src/kernel/pp.cpp @@ -117,6 +117,8 @@ struct pp_fn { template format pp_bnames(It const & begin, It const & end, bool use_line) { + static_assert(std::is_same::value_type, expr>::value, + "pp_bnames takes an argument which is not an iterator containing expr."); auto it = begin; format r = pp_bname(*it); ++it;