From 51c2c69357963ecaffba522aa963a3eba1c3bc8e Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Sat, 5 Jun 2021 23:04:31 +0430 Subject: [PATCH] AK+Everywhere: Disallow constructing Functions from incompatible types Previously, AK::Function would accept _any_ callable type, and try to call it when called, first with the given set of arguments, then with zero arguments, and if all of those failed, it would simply not call the function and **return a value-constructed Out type**. This lead to many, many, many hard to debug situations when someone forgot a `const` in their lambda argument types, and many cases of people taking zero arguments in their lambdas to ignore them. This commit reworks the Function interface to not include any such surprising behaviour, if your function instance is not callable with the declared argument set of the Function, it can simply not be assigned to that Function instance, end of story. --- AK/Function.h | 50 ++++++++++--------- AK/StdLibExtraDetails.h | 7 +++ AK/StdLibExtras.h | 4 -- Meta/Lagom/Fuzzers/FuzzZip.cpp | 2 +- Tests/LibWeb/test-web.cpp | 4 +- Userland/Applications/3DFileViewer/main.cpp | 18 +++---- .../DisplaySettings/FontSettingsWidget.cpp | 4 +- .../Applications/DisplaySettings/main.cpp | 6 +-- .../FileOperationProgressWidget.cpp | 2 +- Userland/Applications/FileManager/main.cpp | 4 +- .../Applications/FontEditor/FontEditor.cpp | 6 +-- .../Applications/FontEditor/NewFontDialog.cpp | 4 +- .../HexEditor/GoToOffsetDialog.cpp | 4 +- .../Applications/Spreadsheet/ExportDialog.cpp | 6 +-- .../Applications/Spreadsheet/ImportDialog.cpp | 6 +-- Userland/Applications/Spreadsheet/main.cpp | 4 +- .../Applications/TextEditor/MainWidget.cpp | 12 ++--- .../Applications/Welcome/WelcomeWidget.cpp | 8 +-- .../Demos/WidgetGallery/GalleryWidget.cpp | 12 ++--- .../HackStudio/Dialogs/NewProjectDialog.cpp | 2 +- Userland/Games/Hearts/Game.cpp | 2 +- Userland/Libraries/LibGUI/FilePicker.cpp | 2 +- .../Libraries/LibGUI/Wizards/WizardDialog.cpp | 6 +-- Userland/Libraries/LibPDF/Parser.cpp | 4 +- Userland/Libraries/LibWeb/DOM/Document.cpp | 2 +- .../Libraries/LibWeb/OutOfProcessWebView.cpp | 2 +- .../Impl/TLSv12WebSocketConnectionImpl.cpp | 6 +-- .../Services/WebSocket/ClientConnection.cpp | 2 +- 28 files changed, 99 insertions(+), 92 deletions(-) diff --git a/AK/Function.h b/AK/Function.h index 06e3f3a75d..612a1906e8 100644 --- a/AK/Function.h +++ b/AK/Function.h @@ -39,26 +39,36 @@ namespace AK { template class Function; +template +inline constexpr bool IsFunctionPointer = (IsPointer && IsFunction>); + +// Not a function pointer, and not an lvalue reference. +template +inline constexpr bool IsFunctionObject = (!IsFunctionPointer && IsRvalueReference); + template class Function { AK_MAKE_NONCOPYABLE(Function); public: Function() = default; + Function(std::nullptr_t) + { + } ~Function() { clear(false); } - template && IsFunction>)&&IsRvalueReference>::Type> - Function(CallableType&& callable) + template + Function(CallableType&& callable) requires((IsFunctionObject && IsCallableWithArguments)) { - init_with_callable(move(callable)); + init_with_callable(forward(callable)); } - template && IsFunction>>::Type> - Function(FunctionType f) + template + Function(FunctionType f) requires((IsFunctionPointer && IsCallableWithArguments, In...>)) { init_with_callable(move(f)); } @@ -68,6 +78,7 @@ public: move_from(move(other)); } + // Note: Despite this method being const, a mutable lambda _may_ modify its own captures. Out operator()(In... in) const { auto* wrapper = callable_wrapper(); @@ -82,16 +93,16 @@ public: explicit operator bool() const { return !!callable_wrapper(); } - template && IsFunction>)&&IsRvalueReference>::Type> - Function& operator=(CallableType&& callable) + template + Function& operator=(CallableType&& callable) requires((IsFunctionObject && IsCallableWithArguments)) { clear(); - init_with_callable(move(callable)); + init_with_callable(forward(callable)); return *this; } - template && IsFunction>>::Type> - Function& operator=(FunctionType f) + template + Function& operator=(FunctionType f) requires((IsFunctionPointer && IsCallableWithArguments, In...>)) { clear(); if (f) @@ -118,7 +129,8 @@ private: class CallableWrapperBase { public: virtual ~CallableWrapperBase() = default; - virtual Out call(In...) const = 0; + // Note: This is not const to allow storing mutable lambdas. + virtual Out call(In...) = 0; virtual void destroy() = 0; virtual void init_and_swap(u8*, size_t) = 0; }; @@ -134,17 +146,9 @@ private: { } - Out call(In... in) const final override + Out call(In... in) final override { - if constexpr (requires { m_callable(forward(in)...); }) { - return m_callable(forward(in)...); - } else if constexpr (requires { m_callable(); }) { - return m_callable(); - } else if constexpr (IsVoid) { - return; - } else { - return {}; - } + return m_callable(forward(in)...); } void destroy() final override @@ -208,10 +212,10 @@ private: VERIFY(m_call_nesting_level == 0); using WrapperType = CallableWrapper; if constexpr (sizeof(WrapperType) > inline_capacity) { - *bit_cast(&m_storage) = new WrapperType(move(callable)); + *bit_cast(&m_storage) = new WrapperType(forward(callable)); m_kind = FunctionKind::Outline; } else { - new (m_storage) WrapperType(move(callable)); + new (m_storage) WrapperType(forward(callable)); m_kind = FunctionKind::Inline; } } diff --git a/AK/StdLibExtraDetails.h b/AK/StdLibExtraDetails.h index d0991b7a2a..8cf43ebbed 100644 --- a/AK/StdLibExtraDetails.h +++ b/AK/StdLibExtraDetails.h @@ -435,10 +435,16 @@ inline constexpr bool IsTrivial = __is_trivial(T); template inline constexpr bool IsTriviallyCopyable = __is_trivially_copyable(T); +template +auto declval() -> T; + +template +inline constexpr bool IsCallableWithArguments = requires(T t) { t(declval()...); }; } using AK::Detail::AddConst; using AK::Detail::Conditional; using AK::Detail::CopyConst; +using AK::Detail::declval; using AK::Detail::DependentFalse; using AK::Detail::EnableIf; using AK::Detail::FalseType; @@ -447,6 +453,7 @@ using AK::Detail::IndexSequence; using AK::Detail::IntegerSequence; using AK::Detail::IsArithmetic; using AK::Detail::IsBaseOf; +using AK::Detail::IsCallableWithArguments; using AK::Detail::IsClass; using AK::Detail::IsConst; using AK::Detail::IsEnum; diff --git a/AK/StdLibExtras.h b/AK/StdLibExtras.h index 7a48da2ba1..19411fc4b6 100644 --- a/AK/StdLibExtras.h +++ b/AK/StdLibExtras.h @@ -39,9 +39,6 @@ struct _RawPtr { namespace AK { -template -auto declval() -> T; - template constexpr T&& forward(RemoveReference& param) { @@ -118,7 +115,6 @@ using RawPtr = typename Detail::_RawPtr::Type; using AK::array_size; using AK::ceil_div; using AK::clamp; -using AK::declval; using AK::exchange; using AK::forward; using AK::max; diff --git a/Meta/Lagom/Fuzzers/FuzzZip.cpp b/Meta/Lagom/Fuzzers/FuzzZip.cpp index 34e1e36a99..e9563ab2d1 100644 --- a/Meta/Lagom/Fuzzers/FuzzZip.cpp +++ b/Meta/Lagom/Fuzzers/FuzzZip.cpp @@ -15,7 +15,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) if (!zip_file.has_value()) return 0; - zip_file->for_each_member([]() { + zip_file->for_each_member([](auto&) { return IterationDecision::Continue; }); diff --git a/Tests/LibWeb/test-web.cpp b/Tests/LibWeb/test-web.cpp index 8155e2c881..17f39bb3b3 100644 --- a/Tests/LibWeb/test-web.cpp +++ b/Tests/LibWeb/test-web.cpp @@ -119,9 +119,9 @@ TESTJS_GLOBAL_FUNCTION(wait_for_page_to_load, waitForPageToLoad) break; } }, - [&](auto) { + [&](auto&, auto) { dbgln("Load of resource {} failed", next_page_to_load.value()); - vm.throw_exception(global_object); + vm.throw_exception(global_object, "Resource load failed"); }); return JS::js_undefined(); diff --git a/Userland/Applications/3DFileViewer/main.cpp b/Userland/Applications/3DFileViewer/main.cpp index 1a98418403..cbe771f75b 100644 --- a/Userland/Applications/3DFileViewer/main.cpp +++ b/Userland/Applications/3DFileViewer/main.cpp @@ -203,23 +203,23 @@ int main(int argc, char** argv) load_model(open_path.value()); })); file_menu.add_separator(); - file_menu.add_action(GUI::CommonActions::make_quit_action([&] { + file_menu.add_action(GUI::CommonActions::make_quit_action([&](auto&) { app->quit(); })); auto& view_menu = menubar->add_menu("&View"); - view_menu.add_action(GUI::CommonActions::make_fullscreen_action([&] { + view_menu.add_action(GUI::CommonActions::make_fullscreen_action([&](auto&) { window->set_fullscreen(!window->is_fullscreen()); })); auto& rotation_axis_menu = view_menu.add_submenu("Rotation &Axis"); - auto rotation_x_action = GUI::Action::create_checkable("&X", [&widget] { + auto rotation_x_action = GUI::Action::create_checkable("&X", [&widget](auto&) { widget.toggle_rotate_x(); }); - auto rotation_y_action = GUI::Action::create_checkable("&Y", [&widget] { + auto rotation_y_action = GUI::Action::create_checkable("&Y", [&widget](auto&) { widget.toggle_rotate_y(); }); - auto rotation_z_action = GUI::Action::create_checkable("&Z", [&widget] { + auto rotation_z_action = GUI::Action::create_checkable("&Z", [&widget](auto&) { widget.toggle_rotate_z(); }); @@ -234,16 +234,16 @@ int main(int argc, char** argv) GUI::ActionGroup rotation_speed_actions; rotation_speed_actions.set_exclusive(true); - auto no_rotation_action = GUI::Action::create_checkable("N&o Rotation", [&widget] { + auto no_rotation_action = GUI::Action::create_checkable("N&o Rotation", [&widget](auto&) { widget.set_rotation_speed(0.f); }); - auto slow_rotation_action = GUI::Action::create_checkable("&Slow", [&widget] { + auto slow_rotation_action = GUI::Action::create_checkable("&Slow", [&widget](auto&) { widget.set_rotation_speed(0.5f); }); - auto normal_rotation_action = GUI::Action::create_checkable("&Normal", [&widget] { + auto normal_rotation_action = GUI::Action::create_checkable("&Normal", [&widget](auto&) { widget.set_rotation_speed(1.f); }); - auto fast_rotation_action = GUI::Action::create_checkable("&Fast", [&widget] { + auto fast_rotation_action = GUI::Action::create_checkable("&Fast", [&widget](auto&) { widget.set_rotation_speed(1.5f); }); diff --git a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp index d3c430a491..5f4898e909 100644 --- a/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp +++ b/Userland/Applications/DisplaySettings/FontSettingsWidget.cpp @@ -25,7 +25,7 @@ FontSettingsWidget::FontSettingsWidget() update_label_with_font(*m_default_font_label, default_font); auto& default_font_button = *find_descendant_of_type_named("default_font_button"); - default_font_button.on_click = [this] { + default_font_button.on_click = [this](auto) { auto font_picker = GUI::FontPicker::construct(window(), &m_default_font_label->font(), false); if (font_picker->exec() == GUI::Dialog::ExecOK) { update_label_with_font(*m_default_font_label, *font_picker->font()); @@ -37,7 +37,7 @@ FontSettingsWidget::FontSettingsWidget() update_label_with_font(*m_fixed_width_font_label, default_fixed_width_font); auto& fixed_width_font_button = *find_descendant_of_type_named("fixed_width_font_button"); - fixed_width_font_button.on_click = [this] { + fixed_width_font_button.on_click = [this](auto) { auto font_picker = GUI::FontPicker::construct(window(), &m_fixed_width_font_label->font(), true); if (font_picker->exec() == GUI::Dialog::ExecOK) { update_label_with_font(*m_fixed_width_font_label, *font_picker->font()); diff --git a/Userland/Applications/DisplaySettings/main.cpp b/Userland/Applications/DisplaySettings/main.cpp index e05b2eb340..554f7173d9 100644 --- a/Userland/Applications/DisplaySettings/main.cpp +++ b/Userland/Applications/DisplaySettings/main.cpp @@ -61,7 +61,7 @@ int main(int argc, char** argv) auto& ok_button = button_container.add("OK"); ok_button.set_fixed_width(75); - ok_button.on_click = [&] { + ok_button.on_click = [&](auto) { background_settings_widget.apply_settings(); monitor_settings_widget.apply_settings(); font_settings_widget.apply_settings(); @@ -70,13 +70,13 @@ int main(int argc, char** argv) auto& cancel_button = button_container.add("Cancel"); cancel_button.set_fixed_width(75); - cancel_button.on_click = [&] { + cancel_button.on_click = [&](auto) { app->quit(); }; auto& apply_button = button_container.add("Apply"); apply_button.set_fixed_width(75); - apply_button.on_click = [&] { + apply_button.on_click = [&](auto) { background_settings_widget.apply_settings(); monitor_settings_widget.apply_settings(); font_settings_widget.apply_settings(); diff --git a/Userland/Applications/FileManager/FileOperationProgressWidget.cpp b/Userland/Applications/FileManager/FileOperationProgressWidget.cpp index 8098c98f52..ab708e4926 100644 --- a/Userland/Applications/FileManager/FileOperationProgressWidget.cpp +++ b/Userland/Applications/FileManager/FileOperationProgressWidget.cpp @@ -34,7 +34,7 @@ FileOperationProgressWidget::FileOperationProgressWidget(NonnullRefPtr("destination_folder_icon"); destination_folder_icon.load_from_file("/res/icons/32x32/filetype-folder-open.png"); - button.on_click = [this] { + button.on_click = [this](auto) { close_pipe(); window()->close(); }; diff --git a/Userland/Applications/FileManager/main.cpp b/Userland/Applications/FileManager/main.cpp index 9c7692724a..720a4b2ac8 100644 --- a/Userland/Applications/FileManager/main.cpp +++ b/Userland/Applications/FileManager/main.cpp @@ -1124,14 +1124,14 @@ int run_in_windowed_mode(RefPtr config, String initial_locatio go_to_location_action->activate(); }; - tree_view.on_drop = [&](const GUI::ModelIndex& index, GUI::DropEvent& event) { + tree_view.on_drop = [&](const GUI::ModelIndex& index, const GUI::DropEvent& event) { if (!event.mime_data().has_urls()) return; auto& target_node = directories_model->node(index); if (!target_node.is_directory()) return; copy_urls_to_directory(event.mime_data().urls(), target_node.full_path()); - event.accept(); + const_cast(event).accept(); }; directory_view.open(initial_location); diff --git a/Userland/Applications/FontEditor/FontEditor.cpp b/Userland/Applications/FontEditor/FontEditor.cpp index 7aae6efb87..f66c58c59b 100644 --- a/Userland/Applications/FontEditor/FontEditor.cpp +++ b/Userland/Applications/FontEditor/FontEditor.cpp @@ -92,7 +92,7 @@ static RefPtr create_font_preview_window(FontEditorWidget& editor) auto& reload_button = textbox_button_container.add(); reload_button.set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/reload.png")); reload_button.set_fixed_width(22); - reload_button.on_click = [&] { + reload_button.on_click = [&](auto) { static int i = 1; if (i >= s_pangram_count) i = 0; @@ -326,7 +326,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& m_glyph_editor_scale_actions.add_action(*m_scale_fifteen_action); m_glyph_editor_scale_actions.set_exclusive(true); - move_glyph_button.on_click = [&] { + move_glyph_button.on_click = [&](auto) { if (move_glyph_button.is_checked()) m_glyph_editor_widget->set_mode(GlyphEditorWidget::Move); else @@ -407,7 +407,7 @@ FontEditorWidget::FontEditorWidget(const String& path, RefPtr&& did_modify_font(); }; - m_weight_combobox->on_change = [this]() { + m_weight_combobox->on_change = [this](auto&, auto&) { m_edited_font->set_weight(GUI::name_to_weight(m_weight_combobox->text())); did_modify_font(); }; diff --git a/Userland/Applications/FontEditor/NewFontDialog.cpp b/Userland/Applications/FontEditor/NewFontDialog.cpp index b15127b279..5ca7d12565 100644 --- a/Userland/Applications/FontEditor/NewFontDialog.cpp +++ b/Userland/Applications/FontEditor/NewFontDialog.cpp @@ -197,7 +197,7 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window) m_glyph_width_spinbox->on_change = [&](int value) { preview_editor.set_preview_size(value, m_glyph_height_spinbox->value()); - deferred_invoke([&] { + deferred_invoke([&](auto&) { m_glyph_editor_container->set_fixed_height(1 + preview_editor.height() + preview_editor.frame_thickness() * 2); }); }; @@ -205,7 +205,7 @@ NewFontDialog::NewFontDialog(GUI::Window* parent_window) preview_editor.set_preview_size(m_glyph_width_spinbox->value(), value); m_mean_line_spinbox->set_max(max(value - 2, 0)); m_baseline_spinbox->set_max(max(value - 2, 0)); - deferred_invoke([&] { + deferred_invoke([&](auto&) { m_glyph_editor_container->set_fixed_height(1 + preview_editor.height() + preview_editor.frame_thickness() * 2); }); }; diff --git a/Userland/Applications/HexEditor/GoToOffsetDialog.cpp b/Userland/Applications/HexEditor/GoToOffsetDialog.cpp index a74a60adc2..fb6a5990b5 100644 --- a/Userland/Applications/HexEditor/GoToOffsetDialog.cpp +++ b/Userland/Applications/HexEditor/GoToOffsetDialog.cpp @@ -137,11 +137,11 @@ GoToOffsetDialog::GoToOffsetDialog() update_statusbar(); }; - m_offset_type_box->on_change = [this]() { + m_offset_type_box->on_change = [this](auto&, auto&) { update_statusbar(); }; - m_offset_from_box->on_change = [this]() { + m_offset_from_box->on_change = [this](auto&, auto&) { update_statusbar(); }; diff --git a/Userland/Applications/Spreadsheet/ExportDialog.cpp b/Userland/Applications/Spreadsheet/ExportDialog.cpp index 965913f101..639eadc5ad 100644 --- a/Userland/Applications/Spreadsheet/ExportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ExportDialog.cpp @@ -89,18 +89,18 @@ CSVExportDialogPage::CSVExportDialogPage(const Sheet& sheet) m_delimiter_tab_radio->on_checked = [&](auto) { update_preview(); }; m_delimiter_space_radio->on_checked = [&](auto) { update_preview(); }; m_delimiter_other_radio->on_checked = [&](auto) { update_preview(); }; - m_delimiter_other_text_box->on_change = [&](auto&) { + m_delimiter_other_text_box->on_change = [&] { if (m_delimiter_other_radio->is_checked()) update_preview(); }; m_quote_single_radio->on_checked = [&](auto) { update_preview(); }; m_quote_double_radio->on_checked = [&](auto) { update_preview(); }; m_quote_other_radio->on_checked = [&](auto) { update_preview(); }; - m_quote_other_text_box->on_change = [&](auto&) { + m_quote_other_text_box->on_change = [&] { if (m_quote_other_radio->is_checked()) update_preview(); }; - m_quote_escape_combo_box->on_change = [&](auto&) { update_preview(); }; + m_quote_escape_combo_box->on_change = [&](auto&, auto&) { update_preview(); }; m_export_header_check_box->on_checked = [&](auto) { update_preview(); }; m_quote_all_fields_check_box->on_checked = [&](auto) { update_preview(); }; diff --git a/Userland/Applications/Spreadsheet/ImportDialog.cpp b/Userland/Applications/Spreadsheet/ImportDialog.cpp index 1237375da2..293ae767cb 100644 --- a/Userland/Applications/Spreadsheet/ImportDialog.cpp +++ b/Userland/Applications/Spreadsheet/ImportDialog.cpp @@ -67,18 +67,18 @@ CSVImportDialogPage::CSVImportDialogPage(StringView csv) m_delimiter_tab_radio->on_checked = [&](auto) { update_preview(); }; m_delimiter_space_radio->on_checked = [&](auto) { update_preview(); }; m_delimiter_other_radio->on_checked = [&](auto) { update_preview(); }; - m_delimiter_other_text_box->on_change = [&](auto&) { + m_delimiter_other_text_box->on_change = [&] { if (m_delimiter_other_radio->is_checked()) update_preview(); }; m_quote_single_radio->on_checked = [&](auto) { update_preview(); }; m_quote_double_radio->on_checked = [&](auto) { update_preview(); }; m_quote_other_radio->on_checked = [&](auto) { update_preview(); }; - m_quote_other_text_box->on_change = [&](auto&) { + m_quote_other_text_box->on_change = [&] { if (m_quote_other_radio->is_checked()) update_preview(); }; - m_quote_escape_combo_box->on_change = [&](auto&) { update_preview(); }; + m_quote_escape_combo_box->on_change = [&](auto&, auto&) { update_preview(); }; m_read_header_check_box->on_checked = [&](auto) { update_preview(); }; m_trim_leading_field_spaces_check_box->on_checked = [&](auto) { update_preview(); }; m_trim_trailing_field_spaces_check_box->on_checked = [&](auto) { update_preview(); }; diff --git a/Userland/Applications/Spreadsheet/main.cpp b/Userland/Applications/Spreadsheet/main.cpp index 8779b05c30..8ed747ee8d 100644 --- a/Userland/Applications/Spreadsheet/main.cpp +++ b/Userland/Applications/Spreadsheet/main.cpp @@ -191,8 +191,8 @@ int main(int argc, char* argv[]) GUI::Clipboard::the().set_data(text_builder.string_view().bytes(), "text/plain", move(metadata)); }; - edit_menu.add_action(GUI::CommonActions::make_copy_action([&] { clipboard_action(false); }, window)); - edit_menu.add_action(GUI::CommonActions::make_cut_action([&] { clipboard_action(true); }, window)); + edit_menu.add_action(GUI::CommonActions::make_copy_action([&](auto&) { clipboard_action(false); }, window)); + edit_menu.add_action(GUI::CommonActions::make_cut_action([&](auto&) { clipboard_action(true); }, window)); edit_menu.add_action(GUI::CommonActions::make_paste_action([&](auto&) { ScopeGuard update_after_paste { [&] { spreadsheet_widget.update(); } }; diff --git a/Userland/Applications/TextEditor/MainWidget.cpp b/Userland/Applications/TextEditor/MainWidget.cpp index 31c8395acd..a62d824160 100644 --- a/Userland/Applications/TextEditor/MainWidget.cpp +++ b/Userland/Applications/TextEditor/MainWidget.cpp @@ -76,20 +76,20 @@ MainWidget::MainWidget() m_replace_textbox->set_placeholder("Replace"); m_match_case_checkbox = *find_descendant_of_type_named("match_case_checkbox"); - m_match_case_checkbox->on_checked = [this] { - m_match_case = m_match_case_checkbox->is_checked(); + m_match_case_checkbox->on_checked = [this](auto is_checked) { + m_match_case = is_checked; }; m_match_case_checkbox->set_checked(true); m_regex_checkbox = *find_descendant_of_type_named("regex_checkbox"); - m_regex_checkbox->on_checked = [this] { - m_use_regex = m_regex_checkbox->is_checked(); + m_regex_checkbox->on_checked = [this](auto is_checked) { + m_use_regex = is_checked; }; m_regex_checkbox->set_checked(false); m_wrap_around_checkbox = *find_descendant_of_type_named("wrap_around_checkbox"); - m_wrap_around_checkbox->on_checked = [this] { - m_should_wrap = m_wrap_around_checkbox->is_checked(); + m_wrap_around_checkbox->on_checked = [this](auto is_checked) { + m_should_wrap = is_checked; }; m_wrap_around_checkbox->set_checked(true); diff --git a/Userland/Applications/Welcome/WelcomeWidget.cpp b/Userland/Applications/Welcome/WelcomeWidget.cpp index 137829665b..0caf473d4d 100644 --- a/Userland/Applications/Welcome/WelcomeWidget.cpp +++ b/Userland/Applications/Welcome/WelcomeWidget.cpp @@ -36,7 +36,7 @@ WelcomeWidget::WelcomeWidget() m_next_button = *find_descendant_of_type_named("next_button"); m_next_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/go-forward.png")); - m_next_button->on_click = [&]() { + m_next_button->on_click = [&](auto) { if (!tip_frame.is_visible()) { m_web_view->set_visible(false); tip_frame.set_visible(true); @@ -51,7 +51,7 @@ WelcomeWidget::WelcomeWidget() m_help_button = *find_descendant_of_type_named("help_button"); m_help_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/book-open.png")); - m_help_button->on_click = []() { + m_help_button->on_click = [](auto) { pid_t pid; const char* argv[] = { "Help", nullptr }; if ((errno = posix_spawn(&pid, "/bin/Help", nullptr, nullptr, const_cast(argv), environ))) { @@ -63,13 +63,13 @@ WelcomeWidget::WelcomeWidget() }; m_new_button = *find_descendant_of_type_named("new_button"); - m_new_button->on_click = [&]() { + m_new_button->on_click = [&](auto) { m_web_view->set_visible(!m_web_view->is_visible()); tip_frame.set_visible(!tip_frame.is_visible()); }; m_close_button = *find_descendant_of_type_named("close_button"); - m_close_button->on_click = []() { + m_close_button->on_click = [](auto) { GUI::Application::the()->quit(); }; diff --git a/Userland/Demos/WidgetGallery/GalleryWidget.cpp b/Userland/Demos/WidgetGallery/GalleryWidget.cpp index bd6715c8e4..1e9c95b947 100644 --- a/Userland/Demos/WidgetGallery/GalleryWidget.cpp +++ b/Userland/Demos/WidgetGallery/GalleryWidget.cpp @@ -82,7 +82,7 @@ GalleryWidget::GalleryWidget() m_disabled_icon_button = basics_tab.find_descendant_of_type_named("disabled_icon_button"); m_disabled_icon_button->set_icon(*m_button_icons[2]); - m_icon_button->on_click = [&]() { + m_icon_button->on_click = [&](auto) { static size_t i; if (i >= m_button_icons.size()) i = 0; @@ -96,7 +96,7 @@ GalleryWidget::GalleryWidget() m_font_button = basics_tab.find_descendant_of_type_named("font_button"); m_font_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/app-font-editor.png")); - m_font_button->on_click = [&]() { + m_font_button->on_click = [&](auto) { auto picker = GUI::FontPicker::construct(window(), &m_text_editor->font(), false); if (picker->exec() == GUI::Dialog::ExecOK) { m_text_editor->set_font(picker->font()); @@ -106,7 +106,7 @@ GalleryWidget::GalleryWidget() m_file_button = basics_tab.find_descendant_of_type_named("file_button"); m_file_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/open.png")); - m_file_button->on_click = [&]() { + m_file_button->on_click = [&](auto) { Optional open_path = GUI::FilePicker::get_open_filepath(window()); if (!open_path.has_value()) return; @@ -116,7 +116,7 @@ GalleryWidget::GalleryWidget() m_input_button = basics_tab.find_descendant_of_type_named("input_button"); m_input_button->set_icon(Gfx::Bitmap::load_from_file("/res/icons/16x16/properties.png")); - m_input_button->on_click = [&]() { + m_input_button->on_click = [&](auto) { String value; if (GUI::InputBox::show(window(), value, "Enter input:", "Input") == GUI::InputBox::ExecOK && !value.is_empty()) m_text_editor->set_text(value); @@ -164,7 +164,7 @@ GalleryWidget::GalleryWidget() m_msgbox_input_type = static_cast(index.row()); }; - m_msgbox_button->on_click = [&]() { + m_msgbox_button->on_click = [&](auto) { GUI::MessageBox::show(window(), m_text_editor->text(), "Message", m_msgbox_type, m_msgbox_input_type); }; @@ -261,7 +261,7 @@ GalleryWidget::GalleryWidget() m_wizard_output->set_text(String::formatted("{}{}", serenityos_ascii, wizard_ascii)); - m_wizard_button->on_click = [&]() { + m_wizard_button->on_click = [&](auto) { StringBuilder sb; sb.append(m_wizard_output->get_text()); sb.append("\nWizard started."); diff --git a/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp b/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp index 9941db1147..512d34db6e 100644 --- a/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp +++ b/Userland/DevTools/HackStudio/Dialogs/NewProjectDialog.cpp @@ -62,7 +62,7 @@ NewProjectDialog::NewProjectDialog(GUI::Window* parent) m_icon_view->on_selection_change = [&]() { update_dialog(); }; - m_icon_view->on_activation = [&]() { + m_icon_view->on_activation = [&](auto&) { if (m_input_valid) do_create_project(); }; diff --git a/Userland/Games/Hearts/Game.cpp b/Userland/Games/Hearts/Game.cpp index 88b4b6f34b..2231679d67 100644 --- a/Userland/Games/Hearts/Game.cpp +++ b/Userland/Games/Hearts/Game.cpp @@ -141,7 +141,7 @@ void Game::show_score_card(bool game_over) button_container.set_layout(); auto& close_button = button_container.add("OK"); - close_button.on_click = [&score_dialog] { + close_button.on_click = [&score_dialog](auto) { score_dialog->done(GUI::Dialog::ExecOK); }; close_button.set_min_width(70); diff --git a/Userland/Libraries/LibGUI/FilePicker.cpp b/Userland/Libraries/LibGUI/FilePicker.cpp index f914c97d35..5830155ee3 100644 --- a/Userland/Libraries/LibGUI/FilePicker.cpp +++ b/Userland/Libraries/LibGUI/FilePicker.cpp @@ -226,7 +226,7 @@ FilePicker::FilePicker(Window* parent_window, Mode mode, const StringView& filen button.set_fixed_height(22); button.set_checkable(true); button.set_exclusive(true); - button.on_click = [this, path] { + button.on_click = [this, path](auto) { set_path(path); }; m_common_location_buttons.append({ path, button }); diff --git a/Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp b/Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp index 7a82f39c21..be4acdff42 100644 --- a/Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp +++ b/Userland/Libraries/LibGUI/Wizards/WizardDialog.cpp @@ -47,13 +47,13 @@ WizardDialog::WizardDialog(Window* parent_window) m_back_button = nav_container_widget.add