Make operator [] take signed int
The built-in operator takes signed int. So, match it, such that
the built-in is never a better or equally-good match to our operator.
Fixes "ambiguous overload" errors from gcc 4.2 and VS 2008.
See https://github.com/harfbuzz/harfbuzz/issues/1374
diff --git a/src/hb-dsalgs.hh b/src/hb-dsalgs.hh
index 4a8144b..9c920fc 100644
--- a/src/hb-dsalgs.hh
+++ b/src/hb-dsalgs.hh
@@ -571,8 +571,9 @@
inline hb_array_t (const hb_array_t &o) : arrayZ (o.arrayZ), len (o.len) {}
inline hb_array_t (Type *array_, unsigned int len_) : arrayZ (array_), len (len_) {}
- inline Type& operator [] (unsigned int i) const
+ inline Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= len)) return Null(Type);
return arrayZ[i];
}
diff --git a/src/hb-open-type.hh b/src/hb-open-type.hh
index f4d0238..ee76d7e 100644
--- a/src/hb-open-type.hh
+++ b/src/hb-open-type.hh
@@ -351,14 +351,16 @@
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE (UnsizedArrayOf, Type);
- inline const Type& operator [] (unsigned int i) const
+ inline const Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
const Type *p = &arrayZ[i];
if (unlikely (p < arrayZ)) return Null (Type); /* Overflowed. */
return *p;
}
- inline Type& operator [] (unsigned int i)
+ inline Type& operator [] (int i_)
{
+ unsigned int i = (unsigned int) i_;
Type *p = &arrayZ[i];
if (unlikely (p < arrayZ)) return Crap (Type); /* Overflowed. */
return *p;
@@ -441,14 +443,16 @@
template <typename Type, typename OffsetType, bool has_null=true>
struct UnsizedOffsetListOf : UnsizedOffsetArrayOf<Type, OffsetType, has_null>
{
- inline const Type& operator [] (unsigned int i) const
+ inline const Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
const OffsetTo<Type, OffsetType, has_null> *p = &this->arrayZ[i];
if (unlikely (p < this->arrayZ)) return Null (Type); /* Overflowed. */
return this+*p;
}
- inline Type& operator [] (unsigned int i)
+ inline Type& operator [] (int i_)
{
+ unsigned int i = (unsigned int) i_;
const OffsetTo<Type, OffsetType, has_null> *p = &this->arrayZ[i];
if (unlikely (p < this->arrayZ)) return Crap (Type); /* Overflowed. */
return this+*p;
@@ -501,13 +505,15 @@
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOf, Type, LenType);
- inline const Type& operator [] (unsigned int i) const
+ inline const Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= len)) return Null (Type);
return arrayZ[i];
}
- inline Type& operator [] (unsigned int i)
+ inline Type& operator [] (int i_)
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= len)) return Crap (Type);
return arrayZ[i];
}
@@ -625,13 +631,15 @@
template <typename Type>
struct OffsetListOf : OffsetArrayOf<Type>
{
- inline const Type& operator [] (unsigned int i) const
+ inline const Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= this->len)) return Null (Type);
return this+this->arrayZ[i];
}
- inline const Type& operator [] (unsigned int i)
+ inline const Type& operator [] (int i_)
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= this->len)) return Crap (Type);
return this+this->arrayZ[i];
}
@@ -668,13 +676,15 @@
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (HeadlessArrayOf, Type, LenType);
- inline const Type& operator [] (unsigned int i) const
+ inline const Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= lenP1 || !i)) return Null (Type);
return arrayZ[i-1];
}
- inline Type& operator [] (unsigned int i)
+ inline Type& operator [] (int i_)
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= lenP1 || !i)) return Crap (Type);
return arrayZ[i-1];
}
@@ -734,13 +744,15 @@
{
HB_NO_CREATE_COPY_ASSIGN_TEMPLATE2 (ArrayOfM1, Type, LenType);
- inline const Type& operator [] (unsigned int i) const
+ inline const Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i > lenM1)) return Null (Type);
return arrayZ[i];
}
- inline Type& operator [] (unsigned int i)
+ inline Type& operator [] (int i_)
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i > lenM1)) return Crap (Type);
return arrayZ[i];
}
@@ -890,13 +902,15 @@
return true;
}
- inline const Type& operator [] (unsigned int i) const
+ inline const Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= get_length ())) return Null (Type);
return StructAtOffset<Type> (&bytesZ, i * header.unitSize);
}
- inline Type& operator [] (unsigned int i)
+ inline Type& operator [] (int i_)
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= get_length ())) return Crap (Type);
return StructAtOffset<Type> (&bytesZ, i * header.unitSize);
}
diff --git a/src/hb-vector.hh b/src/hb-vector.hh
index 313c24c..953a776 100644
--- a/src/hb-vector.hh
+++ b/src/hb-vector.hh
@@ -78,14 +78,16 @@
inline const Type * arrayZ (void) const
{ return arrayZ_ ? arrayZ_ : static_array; }
- inline Type& operator [] (unsigned int i)
+ inline Type& operator [] (int i_)
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= len))
return Crap (Type);
return arrayZ()[i];
}
- inline const Type& operator [] (unsigned int i) const
+ inline const Type& operator [] (int i_) const
{
+ unsigned int i = (unsigned int) i_;
if (unlikely (i >= len))
return Null(Type);
return arrayZ()[i];