Fix int-in-bool-context warning
The values are boundary checked, static cast them to the final type to
avoid compiler emitting warnings.
Test: presubmit
Bug: 148287349
Change-Id: Id1599d0830b6ac5f5049c6e0ca14c60eca0b8e93
diff --git a/aidl_const_expressions.cpp b/aidl_const_expressions.cpp
index 0288a60..afab3a2 100644
--- a/aidl_const_expressions.cpp
+++ b/aidl_const_expressions.cpp
@@ -89,14 +89,14 @@
mOverflowed = true;
return 0;
}
- return mValue / o;
+ return static_cast<T>(mValue / o);
}
T operator%(T o) {
if (o == 0 || (isMin() && o == -1)) {
mOverflowed = true;
return 0;
}
- return mValue % o;
+ return static_cast<T>(mValue % o);
}
T operator|(T o) { return mValue | o; }
T operator^(T o) { return mValue ^ o; }
@@ -112,14 +112,14 @@
mOverflowed = true;
return 0;
}
- return mValue >> o;
+ return static_cast<T>(mValue >> o);
}
T operator<<(T o) {
if (o < 0 || mValue < 0 || o > CLZ(mValue) || o >= static_cast<T>(sizeof(T) * 8)) {
mOverflowed = true;
return 0;
}
- return mValue << o;
+ return static_cast<T>(mValue << o);
}
T operator||(T o) { return mValue || o; }
T operator&&(T o) { return mValue && o; }