From 11d2f49af8f53340134c844173f4d8655b00dea3 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 1 Dec 2018 13:12:21 -0500 Subject: [PATCH] New approach to change BigEndian casts to be int-sized Fixes spurious warnings like: Fixes https://github.com/harfbuzz/harfbuzz/issues/1436 --- src/hb-open-type.hh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh index ee76d7ed8..0038ad8b7 100644 --- a/src/hb-open-type.hh +++ b/src/hb-open-type.hh @@ -52,13 +52,19 @@ namespace OT { * Int types */ +template struct hb_signedness_int; +template <> struct hb_signedness_int { typedef unsigned int value; }; +template <> struct hb_signedness_int { typedef signed int value; }; + /* Integer types in big-endian order and no alignment requirement */ template struct IntType { typedef Type type; - inline void set (Type i) { v.set (i); } - inline operator Type (void) const { return v; } + typedef typename hb_signedness_int::value>::value wide_type; + + inline void set (wide_type i) { v.set (i); } + inline operator wide_type (void) const { return v; } inline bool operator == (const IntType &o) const { return (Type) v == (Type) o.v; } inline bool operator != (const IntType &o) const { return !(*this == o); } static inline int cmp (const IntType *a, const IntType *b) { return b->cmp (*a); } @@ -88,6 +94,8 @@ typedef IntType HBUINT16; /* 16-bit unsigned integer. */ typedef IntType HBINT16; /* 16-bit signed integer. */ typedef IntType HBUINT32; /* 32-bit unsigned integer. */ typedef IntType HBINT32; /* 32-bit signed integer. */ +/* Note: we cannot defined a signed HBINT24 because there's no corresponding C type. + * Works for unsigned, but not signed, since we rely on compiler for sign-extension. */ typedef IntType HBUINT24; /* 24-bit unsigned integer. */ /* 16-bit signed integer (HBINT16) that describes a quantity in FUnits. */