From 762814bd922932d3d9da9b220463b6ce5f167d76 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 20 Jan 2021 20:01:08 +0000 Subject: [PATCH] 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 Reviewed-by: Stephen White Reviewed-by: Austin Eng --- src/common/ityp_array.h | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/ityp_array.h b/src/common/ityp_array.h index 0544de97d6..68b428d5b0 100644 --- a/src/common/ityp_array.h +++ b/src/common/ityp_array.h @@ -44,25 +44,25 @@ namespace ityp { Value& operator[](Index i) { I index = static_cast(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); - ASSERT(index >= 0 && index < Size); + ASSERT(index >= 0 && index < I(Size)); return Base::operator[](index); } Value& at(Index i) { I index = static_cast(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); - ASSERT(index >= 0 && index < Size); + ASSERT(index >= 0 && index < I(Size)); return Base::at(index); } @@ -83,7 +83,7 @@ namespace ityp { } constexpr Index size() const { - return Index(static_cast(Size)); + return Index(I(Size)); } using Base::back;