Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix zlib old-style-cast build breakage #72768

Merged
merged 1 commit into from
Apr 5, 2024
Merged

Fix zlib old-style-cast build breakage #72768

merged 1 commit into from
Apr 5, 2024

Conversation

droe
Copy link
Contributor

@droe droe commented Apr 1, 2024

Summary

Build "Fix zlib old-style-cast build breakage"

Purpose of change

Unbreak the build on at least macOS Sonoma with Xcode 15.2 (15C500b) and zlib 1.3.1 from MacPorts; possibly also on other platform / compiler / zlib combinations:

clang++ -Isrc -isystem src/third-party -DMACOSX -DGIT_VERSION -DOSX_SDL2_LIBS -DTILES -DBACKTRACE -DUSE_HOME_DIR -Og -Werror -Wall -Wextra -Wformat-signedness -Wlogical-op -Wmissing-declarations -Wmissing-noreturn -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wpedantic -Wsuggest-override -Wunused-macros -Wzero-as-null-pointer-constant -Wno-unknown-warning-option -Wno-dangling-reference -Wno-c++20-compat -Wredundant-decls  -g  -fsigned-char -stdlib=libc++ -std=c++17 -DIMGUI_DISABLE_OBSOLETE_KEYIO -mmacosx-version-min=10.13 -D_THREAD_SAFE -I/opt/local/include/SDL2 -I/opt/local/include -I/opt/local/include/opus -I/opt/local/include -I/opt/local/include/opus -I/opt/local/include -I/opt/local/include/SDL2 -DSDL_SOUND -I/opt/local/include/SDL2 -D_THREAD_SAFE -I/opt/local/include -MMD -MP -Winvalid-pch -include-pch pch/main-pch.hpp.pch -c src/cata_utility.cpp -o obj/tiles/cata_utility.o
src/cata_utility.cpp:402:9: error: use of old-style cast [-Werror,-Wold-style-cast]
    if( inflateInit2( &zs, MAX_WBITS | 16 ) != Z_OK ) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/zlib.h:1822:25: note: expanded from macro 'inflateInit2'
                        (int)sizeof(z_stream))
                        ^    ~~~~~~~~~~~~~~~~
1 error generated.
make: *** [obj/tiles/cata_utility.o] Error 1

Describe the solution

Disable -Wold-style-cast across the use of zlib's inflateInit2 macro.

Describe alternatives you've considered

That macro uses a C style cast because it lives in a (C++-compatible) C header, so this isn't a bug in zlib, and even if it were, we'd still want to work around (hypothetically) broken zlib versions.

Considered removing either -Werror or -Wold-style-cast from the defaults, but felt that would be a more contentious change than locally disabling -Wold-style-cast (i.e. the footgunning seems intentional).

Testing

Before change: Build was broken. After change: Build was fine. Smoke-tested the resulting binaries and they seem fine.

Additional context

n/a

Disable -Wold-style-cast across the use of zlib's inflateInit2 macro.
That macro uses a C style cast because it lives in a C++-compatible C
header.

Unbreaks the build on macOS Sonoma with Xcode 15.2 (15C500b) and zlib
1.3.1 from MacPorts.

```
clang++ -Isrc -isystem src/third-party -DMACOSX -DGIT_VERSION -DOSX_SDL2_LIBS -DTILES -DBACKTRACE -DUSE_HOME_DIR -Og -Werror -Wall -Wextra -Wformat-signedness -Wlogical-op -Wmissing-declarations -Wmissing-noreturn -Wnon-virtual-dtor -Wold-style-cast -Woverloaded-virtual -Wpedantic -Wsuggest-override -Wunused-macros -Wzero-as-null-pointer-constant -Wno-unknown-warning-option -Wno-dangling-reference -Wno-c++20-compat -Wredundant-decls  -g  -fsigned-char -stdlib=libc++ -std=c++17 -DIMGUI_DISABLE_OBSOLETE_KEYIO -mmacosx-version-min=10.13 -D_THREAD_SAFE -I/opt/local/include/SDL2 -I/opt/local/include -I/opt/local/include/opus -I/opt/local/include -I/opt/local/include/opus -I/opt/local/include -I/opt/local/include/SDL2 -DSDL_SOUND -I/opt/local/include/SDL2 -D_THREAD_SAFE -I/opt/local/include -MMD -MP -Winvalid-pch -include-pch pch/main-pch.hpp.pch -c src/cata_utility.cpp -o obj/tiles/cata_utility.o
src/cata_utility.cpp:402:9: error: use of old-style cast [-Werror,-Wold-style-cast]
    if( inflateInit2( &zs, MAX_WBITS | 16 ) != Z_OK ) {
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/opt/local/include/zlib.h:1822:25: note: expanded from macro 'inflateInit2'
                        (int)sizeof(z_stream))
                        ^    ~~~~~~~~~~~~~~~~
1 error generated.
make: *** [obj/tiles/cata_utility.o] Error 1
```
@github-actions github-actions bot added [C++] Changes (can be) made in C++. Previously named `Code` new contributor Code: Build Issues regarding different builds and build environments labels Apr 1, 2024
@github-actions github-actions bot added astyled astyled PR, label is assigned by github actions json-styled JSON lint passed, label assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions labels Apr 2, 2024
@Maleclypse Maleclypse merged commit d64e52d into CleverRaven:master Apr 5, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
astyled astyled PR, label is assigned by github actions BasicBuildPassed This PR builds correctly, label assigned by github actions [C++] Changes (can be) made in C++. Previously named `Code` Code: Build Issues regarding different builds and build environments json-styled JSON lint passed, label assigned by github actions new contributor
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants