bees
bees copied to clipboard
Fails to compile without any optimizations (aka -O0)
While testing some compile issues in Gentoo for v0.6.1, I found that bees won't compile with -O0 even in current master:
$ make clean && make LANG="C" CFLAGS="-O0" CXXFLAGS="-O0"
...
In file included from extentwalker.cc:6:
../include/crucible/limits.h: In instantiation of 'To crucible::ranged_cast(From) [with To = long unsigned int; From = long int]':
extentwalker.cc:483:44: required from here
../include/crucible/limits.h:24:35: error: comparison of integer expressions of different signedness: 'long int' and 'long unsigned int' [-Werror=sign-compare]
24 | if (numeric_limits<From>::max() > numeric_limits<To>::max() && numeric_limits<From>::max() < numeric_limits<To>::max()) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/crucible/limits.h:24:94: error: comparison of integer expressions of different signedness: 'long int' and 'long unsigned int' [-Werror=sign-compare]
24 | if (numeric_limits<From>::max() > numeric_limits<To>::max() && numeric_limits<From>::max() < numeric_limits<To>::max()) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/crucible/limits.h:29:35: error: comparison of integer expressions of different signedness: 'long int' and 'long unsigned int' [-Werror=sign-compare]
29 | if (numeric_limits<From>::max() > numeric_limits<To>::max() && f > static_cast<From>(numeric_limits<To>::max())) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/crucible/limits.h: In instantiation of 'To crucible::ranged_cast(From) [with To = long int; From = long long unsigned int]':
extentwalker.cc:529:90: required from here
../include/crucible/limits.h:24:35: error: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long int' [-Werror=sign-compare]
24 | if (numeric_limits<From>::max() > numeric_limits<To>::max() && numeric_limits<From>::max() < numeric_limits<To>::max()) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/crucible/limits.h:24:94: error: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long int' [-Werror=sign-compare]
24 | if (numeric_limits<From>::max() > numeric_limits<To>::max() && numeric_limits<From>::max() < numeric_limits<To>::max()) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
../include/crucible/limits.h:29:35: error: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long int' [-Werror=sign-compare]
29 | if (numeric_limits<From>::max() > numeric_limits<To>::max() && f > static_cast<From>(numeric_limits<To>::max())) {
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors
make[1]: *** [Makefile:48: extentwalker.o] Error 1
make[1]: Leaving directory '/home/kakra/devel/git/src/github.com/Zygo/bees/lib'
Actually, I don't see why that is because -Werror shouldn't depend on the optimization level. It's probably one of the optimization flags that will be enabled at -O1 (it working from level 1 up) but I wasn't able to pin-point which it is (despite comparing gcc -Q --help=optimizers -O.... Maybe it's one of the machine flags. I don't know.
Bees should maybe add the missing gcc flag to successfully compile even without optimizers enabled.
Optimization eliminates unused code branches entirely, so GCC never gets to warn about their behavior. No warning, no error either.
That expression is trying to determine whether it's doing a signed-unsigned comparison when comparing values of the parameter types, and expects the overflow behavior that the warning is about. There's probably a better way to do that, but for now -Wno-error=sign-compare will get the code building.