summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2017-05-12 12:35:16 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2017-05-14 18:43:38 +0200
commita446d76ca4e07cc0255bdd764f381fa7db214475 (patch)
treed2fcabad0248c09621d8d5cc66a1904175144f8a /include
parent45949bf73790b8214a1fcc8492f4ee6faad20780 (diff)
catch out of range values in strong_int constructor
Change-Id: Ibcbb873fda6cb82ad8f575673705ba6cb16217e6 Reviewed-on: https://gerrit.libreoffice.org/37533 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'include')
-rw-r--r--include/o3tl/strong_int.hxx12
1 files changed, 11 insertions, 1 deletions
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; }