skypjack / uvw

Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!
MIT License
1.82k stars 207 forks source link

type_info: avoid gcc-7 `-Wsign-conversion warning` #301

Closed aloisklink closed 12 months ago

aloisklink commented 1 year ago

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<std::uint32_t>(curr_val)) * prime;
                          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

This seems to be a bug in GCC 7.5.0, since newer versions of GCC are fine with it (including GCC 8). Moving the cast to another line fixes the warning, and it should all be compiled down to the same machine code anyway.