X Tutup
Skip to content

BUILD: Use -Werror=return-type (and MSVC equivalent)#6570

Merged
bluegr merged 1 commit intoscummvm:masterfrom
dwatteau:feat/build-gcc-clang-promote-selected-warnings-to-errors
Apr 25, 2025
Merged

BUILD: Use -Werror=return-type (and MSVC equivalent)#6570
bluegr merged 1 commit intoscummvm:masterfrom
dwatteau:feat/build-gcc-clang-promote-selected-warnings-to-errors

Conversation

@dwatteau
Copy link
Contributor

Based on @sluicebox's comment on commit 599fbc2, where a missing return statement was caught by a fatal error in MSVC (thanks to previous PR #4561) but not in the GCC/Clang builds.

This PR now makes the three main builders (configure, MSVC, Xcode) have such a behavior, for this specific case.

configure changes

For the configure scripts, the new flag is set by default, but one can turn it off with --disable-Werror, if some situation requires it (e.g. some Linux distributions having a good reason to do so, some future compiler upgrade introducing a stricter/buggier -Wreturn-type…).

(Regarding CXXFLAGS: I'm not using set_flag_if_supported, since -Werror=flag-name was introduced before GCC 4.7, which is our minimal C++11 requirement.)

Of course, turning a specific warning into a fatal error should only be done when it reveals a dangerous pattern where we want to fail early (to be sure to catch it), and if the compilers don't create frequent false positives for it.

False positives?

Regarding false positives, @lephilousophe mentioned godotengine/godot#58747.

I also saw https://reviews.llvm.org/D98224 mentioning that "some versions of gcc can emit -Wreturn-type warnings on functions that have exhaustive switches over enums" (this seems to be related to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87950, where __builtin_unreachable() is also mentioned).

Anyway, I did some --enable-all-engines tests with:

  • GitHub Actions (Clang, MSVC, GCC 13, GCC 4.8)
  • ./devtools/docker.sh toolchains/riscos (our de-facto oldest toolchain? GCC 4.7)
  • ./devtools/docker.sh toolchains/windows-9x
  • ./devtools/docker.sh toolchains/ps3
  • ./devtools/docker.sh toolchains/windows-9x

and I couldn't find any false-positive case.

…statement

Regarding the `configure` script, we now have:

  * default: add `-Werror=flag-name` for selected warnings where it's
    important to fail early (just `-Werror=return-type` for now)

  * --enable-Werror: use `-Werror` for all warnings

  * --disable-Werror: don't any `-Werror` flag

For Xcode, `-Werror=return-type` is added to default flags.

For MSVC, equivalent flags have been added to the existing
`globalErrors` list.

Suggested by sluicebox.
@bluegr
Copy link
Member

bluegr commented Apr 25, 2025

Nice work! It builds cleanly as well

Thanks, merging

@bluegr bluegr merged commit 7613a63 into scummvm:master Apr 25, 2025
8 checks passed
@dwatteau dwatteau deleted the feat/build-gcc-clang-promote-selected-warnings-to-errors branch April 26, 2025 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup