From fc828e5b3e82650f84d71d8e7b3e183c0524d80c Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Wed, 23 Aug 2023 15:42:28 +0100 Subject: [PATCH] type_info: avoid gcc-7 -Wsign-conversion warning On GCC 7.5.0, the current `uvw::internal::fnv1a()` function throws a `Wsign-conversion` warning, despite us having an explicit cast. ``` src/uvw/type_info.hpp: In function 'constexpr uint32_t uvw::internal::fnv1a(const char*)': src/uvw/type_info.hpp:24:26: warning: conversion to 'unsigned int' from 'char' may change the sign of the result [-Wsign-conversion] value = (value ^ static_cast(curr_val)) * prime; ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ``` This seems to be a bug in GCC 7.5.0, since newer versions of GCC are fine with it. Moving the cast to another line fixes the warning, and it should all be compiled down to the same machine code anyway. --- src/uvw/type_info.hpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/uvw/type_info.hpp b/src/uvw/type_info.hpp index 176dea85..e56cabb7 100644 --- a/src/uvw/type_info.hpp +++ b/src/uvw/type_info.hpp @@ -20,7 +20,8 @@ namespace internal { auto value = offset; while(*curr != 0) { - value = (value ^ static_cast(*(curr++))) * prime; + auto curr_val_int = static_cast(*(curr++)); + value = (value ^ curr_val_int) * prime; } return value;