Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 29 additions & 15 deletions src/ruis/widget/slider/scroll_bar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,40 +94,51 @@ std::vector<utki::shared_ref<ruis::widget>> make_widgets(const utki::shared_ref<
}
} // namespace

// GCC 16 raises a false-positive -Wmaybe-uninitialized in this constructor,
// because values initialized before the use cannot be tracked across the
// base class constructor calls.
// So, we suppress the warning.
#if CFG_COMPILER == CFG_COMPILER_GCC && CFG_COMPILER_VERSION_MAJOR == 16
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif
scroll_bar::scroll_bar( //
const utki::shared_ref<ruis::context>& c,
const utki::shared_ref<ruis::context>& context,
all_parameters params
) :
widget( //
c,
context,
std::move(params.layout_params),
std::move(params.widget)
),
fraction_band_widget( //
context,
this->context,
{
.fraction = params.fraction,
.band_fraction = params.band_fraction //
}
),
oriented(std::move(params.oriented_params)),
container( //
context,
this->context,
{.params = {.layout = layout::pile}},
make_widgets(context)
make_widgets(this->context)
),
handle(this->get_widget("ruis_handle")),
params([&]() {
auto& sbp = params.scroll_bar_params;
if (!sbp.background) {
sbp.background = context.get().loader().load<res::nine_patch>("ruis_npt_slider_bg").to_shared_ptr();
}
if (!sbp.handle) {
sbp.handle = context.get().loader().load<res::nine_patch>("ruis_npt_slider_handle").to_shared_ptr();
}
return params.scroll_bar_params;
}())
params(params.scroll_bar_params)
{
// 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.

this->params.background =
this->context.get().loader().load<res::nine_patch>("ruis_npt_slider_bg").to_shared_ptr();
}
if (!this->params.handle) {
this->params.handle =
this->context.get().loader().load<res::nine_patch>("ruis_npt_slider_handle").to_shared_ptr();
}

auto& np = this->get_widget_as<nine_patch>("ruis_background");
auto& hi = this->get_widget_as<nine_patch>("ruis_handle_image");

Expand Down Expand Up @@ -199,6 +210,9 @@ scroll_bar::scroll_bar( //
return event_status::consumed;
};
}
#if CFG_COMPILER == CFG_COMPILER_GCC && CFG_COMPILER_VERSION_MAJOR == 16
# pragma GCC diagnostic pop
#endif

void scroll_bar::on_fraction_change()
{
Expand Down
Loading