-
Notifications
You must be signed in to change notification settings - Fork 26
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
Upgrade to C23 and adding more static check from compiler #207
Conversation
Used features from C23
GCC/Clang version in some Linux distributions:
Clang and GCC compliance page: |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #207 +/- ##
==========================================
- Coverage 60.13% 60.07% -0.07%
==========================================
Files 24 24
Lines 2757 2760 +3
==========================================
Hits 1658 1658
- Misses 1099 1102 +3 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checks failed at
/__w/ibus-chewing/ibus-chewing/src/setup/ibus-setup-chewing-window.c: In function 'ibus_setup_chewing_window_class_init':
/__w/ibus-chewing/ibus-chewing/src/setup/ibus-setup-chewing-window.c:81:37: error: cast between incompatible function types from 'void (*)(GtkWidget *)' to 'void (*)(GtkWidget *, const char *, GVariant *)' [-Werror=cast-function-type]
81 | (GtkWidgetActionActivateFunc)show_about);
| ^
cc1: all warnings being treated as errors
gmake[2]: *** [bin/CMakeFiles/ibus-setup-chewing.dir/build.make:95: bin/CMakeFiles/ibus-setup-chewing.dir/setup/ibus-setup-chewing-window.c.o] Error 1
This may take longer than expected. I'm still trying to reproduce this failure locally. |
The signature is defined like https://docs.gtk.org/gtk4/callback.WidgetActionActivateFunc.html |
I'm confused why I can not reproduce this error in my local environment (Fedora 40, Clang version 18.1.6)
So it may trigger other compile error after I update the PR later. O_Q |
That's why Werror can be annoying at times : 🤭 |
Now I known that... It's may looks more natural to use the original (signed-integer) type to do comparision. Maybe I should modify the PR again? diff --git a/src/IBusChewingLookupTable.c b/src/IBusChewingLookupTable.c
index 99cec8b..0bdd552 100644
--- a/src/IBusChewingLookupTable.c
+++ b/src/IBusChewingLookupTable.c
@@ -58,8 +58,8 @@ guint ibus_chewing_lookup_table_update(
[[maybe_unused]] IBusChewingProperties *iProperties,
ChewingContext *context) {
IBusText *iText = NULL;
- guint i;
- guint choicePerPage = (guint)chewing_cand_ChoicePerPage(context);
+ gint i;
+ gint choicePerPage = chewing_cand_ChoicePerPage(context);
gint totalChoice = chewing_cand_TotalChoice(context);
gint currentPage = chewing_cand_CurrentPage(context);
diff --git a/src/ibus-chewing-engine.c b/src/ibus-chewing-engine.c
index 7307baf..091495b 100644
--- a/src/ibus-chewing-engine.c
+++ b/src/ibus-chewing-engine.c
@@ -989,7 +989,7 @@ void ibus_chewing_engine_candidate_clicked(IBusEngine *engine, guint index,
if (is_password(self))
return;
- if (index >= (guint)chewing_get_candPerPage(self->icPreEdit->context)) {
+ if ((gint)index >= chewing_get_candPerPage(self->icPreEdit->context)) {
IBUS_CHEWING_LOG(DEBUG, "candidate_clicked() index out of ranged");
return;
} |
Sure, there are opinions that in C/C++ you rarely need to use unsigned integer and it might be dangerous. I'm not sure if the compiler has new warnings against them. It might still worth to follow the wisdom. https://jacobegner.blogspot.com/2019/11/unsigned-integers-are-dangerous.html |
C23 standard provide a cleaner way to express intentions. Change standard from C99 to C23 and modify some preset naming.
- Use empty initializer for null-terminated array, reduce macro usage - For partial value structures, use designated initializer instead
- For setting apply callback functions, just remove variable name - For other cases, use maybe_unused attribute to preserve readability
- Enable extra warning from compiler - Make warning into error in CI build
Rebase and force pushed again.
The |
LGTM |
For motivation, see #206.
This PR contains commits for
-Wextra
and-Werror
compiler optionsIf desired, maybe I can extract the commit that upgrade to C23 as another PR.
Since that it's a standalone change to this project.