From 046c0c91a3ed665531f20955e7cfb86fe5b73213 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 14 Oct 2020 02:51:14 -0400 Subject: input_common/CMakeLists: Make some warnings errors Makes the input_common code warnings consistent with the rest of the codebase. --- src/common/math_util.h | 4 +-- src/common/vector_math.h | 75 ++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 68 insertions(+), 11 deletions(-) (limited to 'src/common') diff --git a/src/common/math_util.h b/src/common/math_util.h index b35ad8507..7cec80d57 100644 --- a/src/common/math_util.h +++ b/src/common/math_util.h @@ -20,8 +20,8 @@ struct Rectangle { constexpr Rectangle() = default; - constexpr Rectangle(T left, T top, T right, T bottom) - : left(left), top(top), right(right), bottom(bottom) {} + constexpr Rectangle(T left_, T top_, T right_, T bottom_) + : left(left_), top(top_), right(right_), bottom(bottom_) {} [[nodiscard]] T GetWidth() const { if constexpr (std::is_floating_point_v) { diff --git a/src/common/vector_math.h b/src/common/vector_math.h index 2a0fcf541..22dba3c2d 100644 --- a/src/common/vector_math.h +++ b/src/common/vector_math.h @@ -87,7 +87,13 @@ public: template [[nodiscard]] constexpr Vec2 operator*(const V& f) const { - return {x * f, y * f}; + using TV = decltype(T{} * V{}); + using C = std::common_type_t; + + return { + static_cast(static_cast(x) * static_cast(f)), + static_cast(static_cast(y) * static_cast(f)), + }; } template @@ -98,7 +104,13 @@ public: template [[nodiscard]] constexpr Vec2 operator/(const V& f) const { - return {x / f, y / f}; + using TV = decltype(T{} / V{}); + using C = std::common_type_t; + + return { + static_cast(static_cast(x) / static_cast(f)), + static_cast(static_cast(y) / static_cast(f)), + }; } template @@ -168,7 +180,10 @@ public: template [[nodiscard]] constexpr Vec2 operator*(const V& f, const Vec2& vec) { - return Vec2(f * vec.x, f * vec.y); + using C = std::common_type_t; + + return Vec2(static_cast(static_cast(f) * static_cast(vec.x)), + static_cast(static_cast(f) * static_cast(vec.y))); } using Vec2f = Vec2; @@ -237,7 +252,14 @@ public: template [[nodiscard]] constexpr Vec3 operator*(const V& f) const { - return {x * f, y * f, z * f}; + using TV = decltype(T{} * V{}); + using C = std::common_type_t; + + return { + static_cast(static_cast(x) * static_cast(f)), + static_cast(static_cast(y) * static_cast(f)), + static_cast(static_cast(z) * static_cast(f)), + }; } template @@ -247,7 +269,14 @@ public: } template [[nodiscard]] constexpr Vec3 operator/(const V& f) const { - return {x / f, y / f, z / f}; + using TV = decltype(T{} / V{}); + using C = std::common_type_t; + + return { + static_cast(static_cast(x) / static_cast(f)), + static_cast(static_cast(y) / static_cast(f)), + static_cast(static_cast(z) / static_cast(f)), + }; } template @@ -367,7 +396,11 @@ public: template [[nodiscard]] constexpr Vec3 operator*(const V& f, const Vec3& vec) { - return Vec3(f * vec.x, f * vec.y, f * vec.z); + using C = std::common_type_t; + + return Vec3(static_cast(static_cast(f) * static_cast(vec.x)), + static_cast(static_cast(f) * static_cast(vec.y)), + static_cast(static_cast(f) * static_cast(vec.z))); } template <> @@ -446,7 +479,15 @@ public: template [[nodiscard]] constexpr Vec4 operator*(const V& f) const { - return {x * f, y * f, z * f, w * f}; + using TV = decltype(T{} * V{}); + using C = std::common_type_t; + + return { + static_cast(static_cast(x) * static_cast(f)), + static_cast(static_cast(y) * static_cast(f)), + static_cast(static_cast(z) * static_cast(f)), + static_cast(static_cast(w) * static_cast(f)), + }; } template @@ -457,7 +498,15 @@ public: template [[nodiscard]] constexpr Vec4 operator/(const V& f) const { - return {x / f, y / f, z / f, w / f}; + using TV = decltype(T{} / V{}); + using C = std::common_type_t; + + return { + static_cast(static_cast(x) / static_cast(f)), + static_cast(static_cast(y) / static_cast(f)), + static_cast(static_cast(z) / static_cast(f)), + static_cast(static_cast(w) / static_cast(f)), + }; } template @@ -582,7 +631,15 @@ public: template [[nodiscard]] constexpr Vec4 operator*(const V& f, const Vec4& vec) { - return {f * vec.x, f * vec.y, f * vec.z, f * vec.w}; + using TV = decltype(V{} * T{}); + using C = std::common_type_t; + + return { + static_cast(static_cast(f) * static_cast(vec.x)), + static_cast(static_cast(f) * static_cast(vec.y)), + static_cast(static_cast(f) * static_cast(vec.z)), + static_cast(static_cast(f) * static_cast(vec.w)), + }; } using Vec4f = Vec4; -- cgit v1.2.3