Bug 708160 - Build failure with GCC 15 (defaults to -std=gnu23) because of bool redefinition
Summary: Build failure with GCC 15 (defaults to -std=gnu23) because of bool redefinition
Status: UNCONFIRMED
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Build Process (show other bugs)
Version: unspecified
Hardware: PC Linux
: P2 normal
Assignee: Chris Liddell (chrisl)
URL:
Keywords:
: 708290 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-11-26 06:55 UTC by Sam James
Modified: 2025-02-11 19:12 UTC (History)
4 users (show)

See Also:
Customer:
Word Size: ---


Attachments
patch for C23 compliance (20.93 KB, patch)
2025-01-08 01:37 UTC, Alex Cherepanov
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2024-11-26 06:55:45 UTC
ghostscript-10.04.0 fails to build with upcoming GCC 15 that defaults to C23 (-std=gnu23). Originally reported downstream in Gentoo at https://bugs.gentoo.org/943857.

In this case, the issue is that `bool` becomes a proper identifier without any includes required:
```
x86_64-pc-linux-gnu-gcc   -O2 -DNDEBUG -Wall -Wstrict-prototypes -Wundef -Wmissing-declarations -Wmissing-prototypes -Wwrite-strings -fno-strict-aliasing -Werror=declaration-after-statement -fno-builtin -fno-common -Werror=return-type -Wno-unused-local-typedefs -DHAVE_STDINT_H=1 -DHAVE_DIRENT_H=1 -DHAVE_SYS_DIR_H=1 -DHAVE_SYS_TIME_H=1 -DHAVE_SYS_TIMES_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_LIBDL=1 -DGX_COLOR_INDEX_TYPE="unsigned long long" -D__USE_UNIX98=1 -DHAVE_SNPRINTF  -O2 -pipe -march=native -fno-diagnostics-color -DHAVE_RESTRICT=1 -fno-strict-aliasing -DHAVE_POPEN_PROTO=1  -I./base -o ./obj/aux/genarch ./base/genarch.c  -lm -ldl  -lidn -lpaper -ltiff -rdynamic -lfontconfig -lfreetype -lfreetype -lopenjp2  -lz
In file included from ./base/genarch.c:22:
./base/stdpre.h:348:13: error: two or more data types in declaration specifiers
  348 | typedef int bool;
      |             ^~~~
./base/stdpre.h:348:1: warning: useless type name in empty declaration
  348 | typedef int bool;
      | ^~~~~~~
make: *** [base/unix-aux.mak:68: obj/aux/genarch] Error 1
```

i.e. the typedef is currently redeclaring bool when it's now a builtin type, so that can't be done.
Comment 1 Chris Liddell (chrisl) 2024-11-26 08:26:37 UTC
It's very irritating that they would default to a standard that's been published for less than a month.

And it's extremely irritating that one of the premier open source projects is defaulting to a standard only available from a (not cheap) paywalled organisation.

:-(

I'll look at this at some point.
Comment 2 Alex Cherepanov 2025-01-08 01:37:06 UTC
Created attachment 26351 [details]
patch for C23 compliance

ghostpdl programs can be tweaked to compile by the current gcc with a few minor changes. The resulting gs executable passed a smoke test, but it has not been tested thoroughly.

I did not fix compiler warnings, such as applying operators ++ or -- to boolean variables. In case of conflicts between function definitions and declarations, the choice between int and bool is not always obvious.

I can continue to work in this bug, fix compiler warnings and look deeper into the distinction between boolean values and integer return codes, providing that there's interest on Artifex part.
Comment 3 Alex Cherepanov 2025-02-11 19:12:35 UTC
*** Bug 708290 has been marked as a duplicate of this bug. ***