Skip to content

widget: fix -Wmaybe-uninitialized error in scroll_bar with GCC 16 - #198

Open
igagis-bot wants to merge 3 commits into
cppfw:mainfrom
igagis-bot:fix-gcc16-scrollbar-warning
Open

igagis-bot wants to merge 3 commits into
cppfw:mainfrom
igagis-bot:fix-gcc16-scrollbar-warning

Conversation

@igagis-bot

Copy link
Copy Markdown
Contributor

GCC 16 raises a false-positive -Wmaybe-uninitialized in the scroll_bar constructor (it cannot track values initialized before the use across base class constructor calls), breaking the build with -Werror.

Move the default resource loading into the constructor body and suppress the warning for GCC 16 (guarded by CFG_COMPILER / CFG_COMPILER_VERSION_MAJOR).

Verified with a full build and the complete test suite (353 ruis tests pass).

GCC 16 raises a false-positive -Wmaybe-uninitialized in the
scroll_bar constructor: it cannot track values initialized before
the use across base class constructor calls. Move the default
resource loading into the constructor body and suppress the
warning for GCC 16.
@codecov

codecov Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 28.56%. Comparing base (f001323) to head (76371ae).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/ruis/widget/slider/scroll_bar.cpp 0.00% 7 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #198      +/-   ##
==========================================
+ Coverage   28.53%   28.56%   +0.02%     
==========================================
  Files         239      239              
  Lines        8943     8942       -1     
  Branches     2785     2785              
==========================================
+ Hits         2552     2554       +2     
+ Misses       6057     6054       -3     
  Partials      334      334              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Comment thread src/ruis/widget/slider/scroll_bar.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this->context style

Comment thread src/ruis/widget/slider/scroll_bar.cpp Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use this->context style

Comment thread src/ruis/widget/slider/scroll_bar.cpp Outdated
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
scroll_bar::scroll_bar( //
const utki::shared_ref<ruis::context>& c,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename c -> context

Use '#'+tab before the pragma directive, as required by the
project's clang-format configuration.
@igagis igagis self-assigned this Nov 27, 2026
// load default resources if not provided
// NOTE: cannot be done in the member initializer list, GCC complains
// about a possibly-uninitialized value there
if (!this->params.background) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly was GCC complaining about? since you moved these out of the initializer list, then why do you suppress warnings with the pragma?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GCC 16 -Wmaybe-uninitialized false positive: in the old code the context base-class member (a utki::shared_ref<ruis::context> initialized by the preceding widget(...) base-class constructor call) was dereferenced via context.get() inside the params([&]{...}()) member initializer. GCC 16 cannot track that the base-class member is already initialized by the time the following initializers run, and reports a possibly-uninitialized read of it, which breaks the build with -Werror.

I moved the loading into the constructor body (where GCC 16 is happy, since the base class is fully constructed there) and kept the pragma as a guard around the whole constructor, because I could not re-verify locally that the body move alone is sufficient on GCC 16 — I only have GCC 14 available here.

If you can confirm that the body move alone is clean on GCC 16, I can drop the pragma in a follow-up commit; happy to also retest on a GCC 16 toolchain if you point me to one.

- rename 'c' parameter to 'context'
- use this->context style in the initializer list and constructor body
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