cameron314 / concurrentqueue

A fast multi-producer, multi-consumer lock-free concurrent queue for C++11
Other
9.87k stars 1.69k forks source link

Compilation warning when compiling with gcc -Wsign-conversion #294

Open Chardrazle opened 2 years ago

Chardrazle commented 2 years ago

-Wsign-conversion This is a quite aggressive gcc compiler warning, but it often detects issues so sometimes we test builds with it switched on. Because the concurrentqueue is header-only the warning permeates across the build. Obviously we can silence this via various means, but it is relatively straight-forward to perform the relevant casts in the code.

The warning occurs on the few lines performing differences with division, such as 2021 and 2965:

    auto offset = static_cast<size_t>(static_cast<typename std::make_signed<index_t>::type>(blockBaseIndex - headBase) / BLOCK_SIZE);

The warning is emitted due to the signed result of blockBaseIndex - headBase being mixed with the unsigned BLOCK_SIZE. Casting BLOCK_SIZE to a signed type would be one possible fix.

(g++ 11.2.1)

cameron314 commented 2 years ago

Let me know if there are more unresolved warnings, I don't have the exact same version of GCC locally.

Chardrazle commented 2 years ago

Looks good. Same warnings appeared on gcc 11.3 when I tried on godbolt. All clean with latest master: https://godbolt.org/z/MdKKf3zGP

Thanks for the quick update, and for sharing your work.