acreloaded / acr

AssaultCube Reloaded (first-person-shooter game)
https://acr.victorz.ca
128 stars 23 forks source link

Compile error with GCC6 #200

Closed susnux closed 8 years ago

susnux commented 8 years ago

I get this error:

[  109s] g++ -fsigned-char -Ofast -fomit-frame-pointer  -fpermissive  -Wall -I. -Ibot -I/usr/include/enet/include -I/usr/include `sdl-config --cflags` -idirafter ../include   -c -o rendertext.o rendertext.cpp
[  109s] rendertext.cpp: In function 'void text_color(char, char*, int, int&, bvec, int)':
[  109s] rendertext.cpp:333:30: error: switch quantity not an integer
[  109s]          switch(abs(stack[sp]))
[  109s]                               ^
[  109s] make: *** [<builtin>: rendertext.o] Error 1

I fixed it for myself by changing to:

switch(abs(static_cast<int>(stack[sp])))
theonlypwner commented 8 years ago

This is strange—stack[sp] should be promoted from char to int to be the argument of int abs(int).

I'm guessing that GCC6 provides a char abs(char) function.

I will include this fix in the future.

susnux commented 8 years ago

hmm maybe gcc brings the float overload into global namespace. It might work to use std::abs explicitly instead of casting.

theonlypwner commented 8 years ago

If GCC6 provides char std::abs(char), then casting is the only way to fix it.

susnux commented 8 years ago

Ok the cast is the best solution, I think it happens because of the new overload: double abs( Integral arg ); so casting to int will use int abs(int) which is the desired one.

theonlypwner commented 8 years ago

Here's how AC addressed this: in assaultcube/AC@752950989b4e286459ca9aee3d61a868d7b20fa4, they created an inline function that implicitly casts to int and calls labs.

As you haven't mentioned other errors with GCC6, I'll fix this specific issue with a cast.