Skip to content

Improve compiler flags for warnings and disable -Wstringop-foo warnings#810

Open
nstoddard wants to merge 2 commits intotmewett:releasefrom
nstoddard:improve-warning-options
Open

Improve compiler flags for warnings and disable -Wstringop-foo warnings#810
nstoddard wants to merge 2 commits intotmewett:releasefrom
nstoddard:improve-warning-options

Conversation

@nstoddard
Copy link
Copy Markdown
Contributor

This brings the warnings produced by GCC closer to those produced by clang. Clang still generates a few warnings that GCC doesn't seem to support, however.

This also disables -Wstringop-truncation, -overread, and -overflow, since the resulting warnings are probably useless. Clang doesn't support those flags, so this unfortunately has to be done with #pragmas in Rogue.h.

I recommend not merging this until #789 is merged, because that PR fixes dozens of warnings that currently only show up in Clang, and this PR will enable those warnings in GCC.

This brings the warnings produced by GCC closer to those produced by clang. Clang still generates a few warnings that GCC doesn't seem to support, however.

This also disables -Wstringop-truncation, -overread, and -overflow, since the resulting warnings are probably useless. Clang doesn't support those flags, so this unfortunately has to be done with `#pragma`s in `Rogue.h`.
@tmewett
Copy link
Copy Markdown
Owner

tmewett commented Mar 3, 2026

I don't understand the disabling in the header file thing.. are the -Wstringop-* warnings coming from an umbrella -W? Won't compilers just ignore a -W that they don't understand?

@nstoddard
Copy link
Copy Markdown
Contributor Author

I don't understand the disabling in the header file thing.. are the -Wstringop-* warnings coming from an umbrella -W? Won't compilers just ignore a -W that they don't understand?

The stringop warnings seem to be enabled by default in GCC. And unfortunately Clang does not ignore unknown warning flags; instead it prints the following for every single file:

warning: unknown warning option '-Wstringop-truncation'; did you mean '-Wformat-truncation'? [-Wunknown-warning-option]
warning: unknown warning option '-Wstringop-overread' [-Wunknown-warning-option]
warning: unknown warning option '-Wstringop-overflow'; did you mean '-Wshift-overflow'? [-Wunknown-warning-option]

From those messages, you'd think we could just add -Wno-unknown-warning-option to the Makefile. And that does in fact get rid of these warnings in Clang. But unfortunately, doing so causes GCC to print a bunch of the following:

cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics

Also, using a #pragma to ignore -Wunknown-warning-option in Clang doesn't seem to work, for some reason.

Not sure what the compiler developers were thinking here. Unfortunately I don't see a less ugly way to handle this.

@tmewett
Copy link
Copy Markdown
Owner

tmewett commented Mar 8, 2026

instead it prints the following for every single file

I don't understand why clang is printing a warning for a flag that doesn't appear on the command line 🤔

@nstoddard
Copy link
Copy Markdown
Contributor Author

instead it prints the following for every single file

I don't understand why clang is printing a warning for a flag that doesn't appear on the command line 🤔

Oops, I edited the Makefile incorrectly for that particular test (I accidentally included -Wstringop-truncation instead of -Wno-stringop-truncation etc). But if the Makefile includes -Wno-stringop-truncation -Wno-stringop-overread -Wno-stringop-overflow, it still prints lines like warning: unknown warning option '-Wno-stringop-truncation'; did you mean '-Wno-format-truncation'? [-Wunknown-warning-option].

If these warning flags are disabled using #pragmas instead of in the Makefile, no such messages are printed.

@tmewett
Copy link
Copy Markdown
Owner

tmewett commented Mar 24, 2026

Ok, I think this makes sense, let's do it. I'll merge when the conflicts are fixed

@nstoddard nstoddard force-pushed the improve-warning-options branch from 86faf2d to 7691f58 Compare March 27, 2026 22:58
@nstoddard
Copy link
Copy Markdown
Contributor Author

I fixed the merge conflicts. I sorted the warning flags a bit differently than before (e.g. grouping together prototype-related flags instead of grouping together all -Werror=foo flags). I have a slight preference for organizing them like this, but let me know if I should change it to be more similar to how it was.

@nstoddard nstoddard force-pushed the improve-warning-options branch from 7691f58 to 169ab7d Compare March 27, 2026 23:16
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