ityp_array: Allow using a T whose underlying type is signed.
When trying to use ityp_array with an enum class whose underlying
type is int, warnings were fired because of a comparison between signed
and unsigned integers. Fix this by explicitly casting Size to `I` using
a constructor cast.
Bug: dawn:635
Change-Id: I5ee0101684e5847ec5ec6f71a9657fcce839a2a5
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/38106
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
diff --git a/src/common/ityp_array.h b/src/common/ityp_array.h
index 0544de9..68b428d 100644
--- a/src/common/ityp_array.h
+++ b/src/common/ityp_array.h
@@ -44,25 +44,25 @@
Value& operator[](Index i) {
I index = static_cast<I>(i);
- ASSERT(index >= 0 && index < Size);
+ ASSERT(index >= 0 && index < I(Size));
return Base::operator[](index);
}
constexpr const Value& operator[](Index i) const {
I index = static_cast<I>(i);
- ASSERT(index >= 0 && index < Size);
+ ASSERT(index >= 0 && index < I(Size));
return Base::operator[](index);
}
Value& at(Index i) {
I index = static_cast<I>(i);
- ASSERT(index >= 0 && index < Size);
+ ASSERT(index >= 0 && index < I(Size));
return Base::at(index);
}
constexpr const Value& at(Index i) const {
I index = static_cast<I>(i);
- ASSERT(index >= 0 && index < Size);
+ ASSERT(index >= 0 && index < I(Size));
return Base::at(index);
}
@@ -83,7 +83,7 @@
}
constexpr Index size() const {
- return Index(static_cast<I>(Size));
+ return Index(I(Size));
}
using Base::back;