-
Notifications
You must be signed in to change notification settings - Fork 33
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 a couple of compilation warnings when building with clang #520
Merged
+57
−46
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Declaring variables inside switch statement requires a new block (at least before the C23 extensions were introduced): $ CC=clang meson build --werror -Dc_args=-Wno-deprecated-declarations ... $ ninja -C build ninja: Entering directory `build' [24/84] Generating glib marshaller header src/polkitagent/polkitagentmarshal_h INFO: Reading ../src/polkitagent/polkitagentmarshal.list... [25/84] Generating glib marshaller source src/polkitagent/polkitagentmarshal_c INFO: Reading ../src/polkitagent/polkitagentmarshal.list... [53/84] Compiling C object src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendactionpool.c.o FAILED: src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendactionpool.c.o clang -Isrc/polkitbackend/libpolkit-backend-1.a.p -Isrc/polkitbackend -I../src/polkitbackend -I. -I.. -Isrc -I../src -Isrc/polkit -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c99 -O2 -g -D_GNU_SOURCE -include config.h -Waggregate-return -Wdeclaration-after-statement -Wformat=2 -Wimplicit-function-declaration -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wstrict-prototypes -Wno-format-y2k -Wno-declaration-after-statement -Wno-deprecated-declarations -fPIC -pthread -DWITH_GZFILEOP -D_POLKIT_COMPILATION -D_POLKIT_BACKEND_COMPILATION '-DPACKAGE_DATA_DIR="/usr/share"' '-DPACKAGE_SYSCONF_DIR="/etc"' -MD -MQ src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendactionpool.c.o -MF src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendactionpool.c.o.d -o src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendactionpool.c.o -c ../src/polkitbackend/polkitbackendactionpool.c ../src/polkitbackend/polkitbackendactionpool.c:264:7: error: label followed by a declaration is a C23 extension [-Werror,-Wc23-extensions] 264 | const gchar **dir_names = (const gchar**) g_value_get_boxed (value); | ^ 1 error generated. Follow-up for 9958c25.
Which allows correct type-checking during compilation and avoids errors when building with clang + -Werror: [58/71] Compiling C object src/programs/pkexec.p/pkexec.c.o FAILED: src/programs/pkexec.p/pkexec.c.o clang -Isrc/programs/pkexec.p -Isrc/programs -I../src/programs -I. -I.. -Isrc/polkitagent -I../src/polkitagent -Isrc -I../src -Isrc/polkit -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c99 -O2 -g -D_GNU_SOURCE -include config.h -Waggregate-return -Wdeclaration-after-statement -Wformat=2 -Wimplicit-function-declaration -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wstrict-prototypes -Wno-format-y2k -Wno-declaration-after-statement -Wno-deprecated-declarations -pthread -DWITH_GZFILEOP -MD -MQ src/programs/pkexec.p/pkexec.c.o -MF src/programs/pkexec.p/pkexec.c.o.d -o src/programs/pkexec.p/pkexec.c.o -c ../src/programs/pkexec.c ../src/programs/pkexec.c:109:25: error: format string is not a string literal [-Werror,-Wformat-nonliteral] 109 | s = g_strdup_vprintf (format, var_args); | ^~~~~~ 1 error generated. [59/71] Compiling C object src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o FAILED: src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o clang -Isrc/polkitbackend/libpolkit-backend-1.a.p -Isrc/polkitbackend -I../src/polkitbackend -I. -I.. -Isrc -I../src -Isrc/polkit -I/usr/include/glib-2.0 -I/usr/lib64/glib-2.0/include -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/sysprof-6 -I/usr/include/gio-unix-2.0 -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Werror -std=c99 -O2 -g -D_GNU_SOURCE -include config.h -Waggregate-return -Wdeclaration-after-statement -Wformat=2 -Wimplicit-function-declaration -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wmissing-prototypes -Wstrict-prototypes -Wno-format-y2k -Wno-declaration-after-statement -Wno-deprecated-declarations -fPIC -pthread -DWITH_GZFILEOP -D_POLKIT_COMPILATION -D_POLKIT_BACKEND_COMPILATION '-DPACKAGE_DATA_DIR="/usr/share"' '-DPACKAGE_SYSCONF_DIR="/etc"' -MD -MQ src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o -MF src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o.d -o src/polkitbackend/libpolkit-backend-1.a.p/polkitbackendauthority.c.o -c ../src/polkitbackend/polkitbackendauthority.c ../src/polkitbackend/polkitbackendauthority.c:1721:31: error: format string is not a string literal [-Werror,-Wformat-nonliteral] 1721 | message = g_strdup_vprintf (format, var_args); | ^~~~~~ 1 error generated.
mrc0mmand
changed the title
Fix a couple of compilationq warnings when building with clang
Fix a couple of compilation warnings when building with clang
Nov 4, 2024
mrc0mmand
force-pushed
the
fix-clang-warnings
branch
3 times, most recently
from
November 4, 2024 13:46
305b3cd
to
f2e7683
Compare
setre*id() functions are declared with `warn_unused_result` which makes them emit a warning when their result is unused. This warning can be suppressed by using (void) cast in clang, so do this where appropriate. As gcc doesn't support this, disable the warning completely when gcc is used. See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425
mrc0mmand
force-pushed
the
fix-clang-warnings
branch
from
November 4, 2024 13:52
f2e7683
to
e186887
Compare
Suppress the outstanding -Wdeprecated-declarations warnings for now, so we don't miss real issues in the future.
These were fixed by dropping mocklibc.
mrc0mmand
force-pushed
the
fix-clang-warnings
branch
from
November 4, 2024 13:56
e186887
to
a3c8ade
Compare
I think it would be great if it was possible to bring back clang in https://packit.dev/posts/openscanhub-prototype to be able to see all the clang warnings fixed in PRs (when |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There's still a bunch of warnings caused by
-Wdeprecated-declarations
, but these can be easily suppressed by-Dc_args=-Wno-deprecated-declarations
for now.This PR also tweaks the CI jobs to build with
-Werror
, so we should be able to catch these kind of issues a bit earlier in the future.