tmewett / BrogueCE

Brogue: Community Edition - a community-lead fork of the much-loved minimalist roguelike game
https://sites.google.com/site/broguegame/
GNU Affero General Public License v3.0
942 stars 100 forks source link

Incompatible const pointer warnings (ERRORS on GCC 14) #696

Open mattiarmston opened 3 weeks ago

mattiarmston commented 3 weeks ago

I have compiled and installed version 1.13 and wanted to contribute however when compiling HEAD I ran into the errors below. I am able to compile earlier versions and using git bisect I found the first commit to cause this error on my machine is 9c35671.

Running make bin/brogue outputs multiple errors such as:

src/brogue/Movement.c: In function ‘handleWhipAttacks’:
src/brogue/Movement.c:670:29: error: passing argument 1 of ‘abortAttack’ from incompatible pointer type [-Wincompatible-pointer-types]
  670 |             if (abortAttack(hitList)) {
      |                             ^~~~~~~
      |                             |
      |                             creature **
src/brogue/Movement.c:614:44: note: expected ‘const creature **’ but argument is of type ‘creature **’
  614 | static boolean abortAttack(const creature *hitList[8]) {
      |                            ~~~~~~~~~~~~~~~~^~~~~~~~~~

I am using Arch Linux, GCC version 14.1.1 and GNU Make version 4.4.1.

Could you please point out what I have missed or done wrong.

Matti

tmewett commented 3 weeks ago

So I just tested on my current GCC 13 and I also get those messages, but as warnings, not errors. Then I upgraded to 14 and now they're errors.

By default, in C99 and later dialects of C, GCC treats this issue as an error. The error can be downgraded to a warning using -fpermissive (along with certain other errors), or for this error alone, with -Wno-error=incompatible-pointer-types. (source)

So that's fun. It turns out that while T* is convertible to const T*, T** is not convertible to const T** !

So you've not done anything wrong - we should add -Wno-error=incompatible-pointer-types to the Makefile cflags for now, and fix those pointer incompatibilities. You can continue building locally by adding that flag.