From a446d76ca4e07cc0255bdd764f381fa7db214475 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Fri, 12 May 2017 12:35:16 +0200 Subject: catch out of range values in strong_int constructor Change-Id: Ibcbb873fda6cb82ad8f575673705ba6cb16217e6 Reviewed-on: https://gerrit.libreoffice.org/37533 Tested-by: Jenkins Reviewed-by: Noel Grandin --- include/o3tl/strong_int.hxx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'include/o3tl') diff --git a/include/o3tl/strong_int.hxx b/include/o3tl/strong_int.hxx index ff2ba9123627..ce5466e45167 100644 --- a/include/o3tl/strong_int.hxx +++ b/include/o3tl/strong_int.hxx @@ -21,6 +21,8 @@ #define INCLUDED_O3TL_STRONG_INT_HXX #include +#include +#include namespace o3tl { @@ -40,7 +42,15 @@ template struct strong_int { public: - explicit constexpr strong_int(UNDERLYING_TYPE value) : m_value(value) {} + explicit constexpr strong_int(long value) : m_value(value) + { +#if HAVE_CXX14_CONSTEXPR + // catch attempts to pass in out-of-range values early + assert(value >= std::numeric_limits::min() + && value <= std::numeric_limits::max() + && "out of range"); +#endif + } strong_int() : m_value(0) {} explicit constexpr operator UNDERLYING_TYPE() const { return m_value; } -- cgit