include/o3tl/strong_int.hxx | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-)
New commits: commit a446d76ca4e07cc0255bdd764f381fa7db214475 Author: Noel Grandin <noel.gran...@collabora.co.uk> Date: Fri May 12 12:35:16 2017 +0200 catch out of range values in strong_int constructor Change-Id: Ibcbb873fda6cb82ad8f575673705ba6cb16217e6 Reviewed-on: https://gerrit.libreoffice.org/37533 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> 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 <sal/config.h> +#include <limits> +#include <cassert> namespace o3tl { @@ -40,7 +42,15 @@ template <typename UNDERLYING_TYPE, typename PHANTOM_TYPE> 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<UNDERLYING_TYPE>::min() + && value <= std::numeric_limits<UNDERLYING_TYPE>::max() + && "out of range"); +#endif + } strong_int() : m_value(0) {} explicit constexpr operator UNDERLYING_TYPE() const { return m_value; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits