From 7b01acdb81ca380d22df3fec9da7a6f1d13d77f2 Mon Sep 17 00:00:00 2001 From: Davide Pesavento Date: Sun, 20 Jul 2025 18:01:22 -0400 Subject: [PATCH] Make all single-argument constructors explicit --- src/common/binary_reader_writer.h | 12 ++++++------ src/common/dynamic_library.h | 2 +- src/common/file_system.h | 4 ++-- src/common/heap_array.h | 4 ++-- src/common/perf_scope.h | 2 +- src/core/analog_controller.h | 2 +- src/core/cheats.cpp | 6 +++--- src/core/controller.h | 2 +- src/core/ddgo_controller.h | 2 +- src/core/fullscreen_ui.h | 2 +- src/core/gpu_sw.h | 2 +- src/core/guncon.h | 2 +- src/core/jogcon.h | 2 +- src/core/negcon.h | 2 +- src/core/negcon_rumble.h | 4 ++-- src/core/playstation_mouse.h | 2 +- src/duckstation-qt/controllerbindingwidgets.h | 4 ++-- src/duckstation-qt/debuggermodels.h | 8 ++++---- src/duckstation-qt/gamelistrefreshthread.h | 7 +++---- src/duckstation-qt/gamelistwidget.cpp | 2 +- src/duckstation-qt/gamelistwidget.h | 2 +- src/duckstation-qt/inputbindingwidgets.h | 4 ++-- src/duckstation-qt/isobrowserwindow.h | 2 +- src/duckstation-qt/qthost.h | 4 ++-- src/duckstation-qt/qtprogresscallback.h | 4 ++-- src/duckstation-qt/selectdiscdialog.h | 2 +- src/updater/updater.h | 2 +- src/util/cd_image_cue.cpp | 2 +- src/util/gpu_device.h | 2 +- src/util/postprocessing.h | 2 +- src/util/postprocessing_shader.h | 4 ++-- 31 files changed, 51 insertions(+), 52 deletions(-) diff --git a/src/common/binary_reader_writer.h b/src/common/binary_reader_writer.h index ec83d92bf..b3ff2914b 100644 --- a/src/common/binary_reader_writer.h +++ b/src/common/binary_reader_writer.h @@ -16,7 +16,7 @@ class BinarySpanReader { public: BinarySpanReader(); - BinarySpanReader(std::span buf); + explicit BinarySpanReader(std::span buf); BinarySpanReader(const BinarySpanReader&) = delete; BinarySpanReader& operator=(const BinarySpanReader&) = delete; @@ -146,7 +146,7 @@ class BinarySpanWriter { public: BinarySpanWriter(); - BinarySpanWriter(std::span buf); + explicit BinarySpanWriter(std::span buf); BinarySpanWriter(const BinarySpanWriter&) = delete; BinarySpanWriter& operator=(const BinarySpanWriter&) = delete; @@ -217,8 +217,8 @@ class BinaryFileReader { public: BinaryFileReader(); - BinaryFileReader(std::FILE* fp); - + explicit BinaryFileReader(std::FILE* fp); + BinaryFileReader(const BinaryFileReader&) = delete; BinaryFileReader& operator=(const BinaryFileReader&) = delete; @@ -308,8 +308,8 @@ class BinaryFileWriter { public: BinaryFileWriter(); - BinaryFileWriter(std::FILE* fp); - + explicit BinaryFileWriter(std::FILE* fp); + BinaryFileWriter(const BinaryFileWriter&) = delete; BinaryFileWriter& operator=(const BinaryFileWriter&) = delete; diff --git a/src/common/dynamic_library.h b/src/common/dynamic_library.h index 4cc40adab..ecfc649b9 100644 --- a/src/common/dynamic_library.h +++ b/src/common/dynamic_library.h @@ -19,7 +19,7 @@ public: DynamicLibrary(); /// Automatically loads the specified library. Call IsOpen() to check validity before use. - DynamicLibrary(const char* filename); + explicit DynamicLibrary(const char* filename); /// Move constructor, transfers ownership. DynamicLibrary(DynamicLibrary&& move); diff --git a/src/common/file_system.h b/src/common/file_system.h index 5d3b5852d..5a7ea5f65 100644 --- a/src/common/file_system.h +++ b/src/common/file_system.h @@ -165,8 +165,8 @@ class POSIXLock { public: POSIXLock(); - POSIXLock(int fd, bool block = true, Error* error = nullptr); - POSIXLock(std::FILE* fp, bool block = true, Error* error = nullptr); + explicit POSIXLock(int fd, bool block = true, Error* error = nullptr); + explicit POSIXLock(std::FILE* fp, bool block = true, Error* error = nullptr); POSIXLock(POSIXLock&& move); POSIXLock(const POSIXLock&) = delete; ~POSIXLock(); diff --git a/src/common/heap_array.h b/src/common/heap_array.h index fa9935661..62dce35de 100644 --- a/src/common/heap_array.h +++ b/src/common/heap_array.h @@ -167,7 +167,7 @@ public: using this_type = DynamicHeapArray; DynamicHeapArray() : m_data(nullptr), m_size(0) {} - DynamicHeapArray(size_t size) { internal_resize(size, nullptr, 0); } + explicit DynamicHeapArray(size_t size) { internal_resize(size, nullptr, 0); } DynamicHeapArray(const T* begin, const T* end) { const size_t size = reinterpret_cast(end) - reinterpret_cast(begin); @@ -195,7 +195,7 @@ public: m_size = 0; } } - DynamicHeapArray(const std::span data) + explicit DynamicHeapArray(const std::span data) { if (!data.empty()) { diff --git a/src/common/perf_scope.h b/src/common/perf_scope.h index b85d54d83..1b1219c1f 100644 --- a/src/common/perf_scope.h +++ b/src/common/perf_scope.h @@ -8,7 +8,7 @@ class PerfScope { public: - constexpr PerfScope(const char* prefix) : m_prefix(prefix) {} + constexpr explicit PerfScope(const char* prefix) : m_prefix(prefix) {} bool HasPrefix() const { return (m_prefix && m_prefix[0]); } void Register(const void* ptr, size_t size, const char* symbol); diff --git a/src/core/analog_controller.h b/src/core/analog_controller.h index 60f003537..aa3b2d80b 100644 --- a/src/core/analog_controller.h +++ b/src/core/analog_controller.h @@ -60,7 +60,7 @@ public: static const Controller::ControllerInfo INFO; - AnalogController(u32 index); + explicit AnalogController(u32 index); ~AnalogController() override; static std::unique_ptr Create(u32 index); diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 4fbc93aad..3758190c6 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -32,7 +32,7 @@ namespace { class CheatFileReader { public: - CheatFileReader(const std::string_view contents) : m_contents(contents) {} + explicit CheatFileReader(const std::string_view contents) : m_contents(contents) {} ALWAYS_INLINE size_t GetCurrentOffset() const { return m_current_offset; } ALWAYS_INLINE size_t GetCurrentLineOffset() const { return m_current_line_offset; } @@ -178,7 +178,7 @@ public: }; public: - CheatCode(Metadata metadata); + explicit CheatCode(Metadata metadata); virtual ~CheatCode(); ALWAYS_INLINE const Metadata& GetMetadata() const { return m_metadata; } @@ -2034,7 +2034,7 @@ namespace { class GamesharkCheatCode final : public CheatCode { public: - GamesharkCheatCode(Metadata metadata); + explicit GamesharkCheatCode(Metadata metadata); ~GamesharkCheatCode() override; static std::unique_ptr Parse(Metadata metadata, const std::string_view data, Error* error); diff --git a/src/core/controller.h b/src/core/controller.h index 64c88df36..d101ead2e 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -53,7 +53,7 @@ public: static constexpr float DEFAULT_STICK_SENSITIVITY = 1.33f; static constexpr float DEFAULT_BUTTON_DEADZONE = 0.25f; - Controller(u32 index); + explicit Controller(u32 index); virtual ~Controller(); /// Returns the type of controller. diff --git a/src/core/ddgo_controller.h b/src/core/ddgo_controller.h index a2e327e71..53f5812ee 100644 --- a/src/core/ddgo_controller.h +++ b/src/core/ddgo_controller.h @@ -57,7 +57,7 @@ public: static const Controller::ControllerInfo INFO; - DDGoController(u32 index); + explicit DDGoController(u32 index); ~DDGoController() override; static std::unique_ptr Create(u32 index); diff --git a/src/core/fullscreen_ui.h b/src/core/fullscreen_ui.h index 7a7b14ce3..7769aa638 100644 --- a/src/core/fullscreen_ui.h +++ b/src/core/fullscreen_ui.h @@ -84,7 +84,7 @@ void SetStandardSelectionFooterText(bool back_instead_of_cancel); class BackgroundProgressCallback final : public ProgressCallback { public: - BackgroundProgressCallback(std::string name); + explicit BackgroundProgressCallback(std::string name); ~BackgroundProgressCallback() override; void SetStatusText(const std::string_view text) override; diff --git a/src/core/gpu_sw.h b/src/core/gpu_sw.h index dd68e55bc..ef8c718f4 100644 --- a/src/core/gpu_sw.h +++ b/src/core/gpu_sw.h @@ -17,7 +17,7 @@ class GPU_SW final : public GPUBackend { public: - GPU_SW(GPUPresenter& presenter); + explicit GPU_SW(GPUPresenter& presenter); ~GPU_SW() override; bool Initialize(bool upload_vram, Error* error) override; diff --git a/src/core/guncon.h b/src/core/guncon.h index 1e3ec0b36..9b3c6ba35 100644 --- a/src/core/guncon.h +++ b/src/core/guncon.h @@ -27,7 +27,7 @@ public: static const Controller::ControllerInfo INFO; - GunCon(u32 index); + explicit GunCon(u32 index); ~GunCon() override; static std::unique_ptr Create(u32 index); diff --git a/src/core/jogcon.h b/src/core/jogcon.h index 0af8bf9b5..6187cc82d 100644 --- a/src/core/jogcon.h +++ b/src/core/jogcon.h @@ -43,7 +43,7 @@ public: static const Controller::ControllerInfo INFO; - JogCon(u32 index); + explicit JogCon(u32 index); ~JogCon() override; static std::unique_ptr Create(u32 index); diff --git a/src/core/negcon.h b/src/core/negcon.h index a2393ce8d..286aa12c4 100644 --- a/src/core/negcon.h +++ b/src/core/negcon.h @@ -81,7 +81,7 @@ public: static const Controller::ControllerInfo INFO; - NeGcon(u32 index); + explicit NeGcon(u32 index); ~NeGcon() override; static std::unique_ptr Create(u32 index); diff --git a/src/core/negcon_rumble.h b/src/core/negcon_rumble.h index d823aec8c..e3105150e 100644 --- a/src/core/negcon_rumble.h +++ b/src/core/negcon_rumble.h @@ -49,7 +49,7 @@ public: static const Controller::ControllerInfo INFO; - NeGconRumble(u32 index); + explicit NeGconRumble(u32 index); ~NeGconRumble() override; static std::unique_ptr Create(u32 index); @@ -148,4 +148,4 @@ private: float m_steering_deadzone = 0.00f; float m_steering_sensitivity = 1.00f; -}; \ No newline at end of file +}; diff --git a/src/core/playstation_mouse.h b/src/core/playstation_mouse.h index 3a412cef6..d6f156ae2 100644 --- a/src/core/playstation_mouse.h +++ b/src/core/playstation_mouse.h @@ -23,7 +23,7 @@ public: static const Controller::ControllerInfo INFO; - PlayStationMouse(u32 index); + explicit PlayStationMouse(u32 index); ~PlayStationMouse() override; static std::unique_ptr Create(u32 index); diff --git a/src/duckstation-qt/controllerbindingwidgets.h b/src/duckstation-qt/controllerbindingwidgets.h index 4a4787d34..d8d8226df 100644 --- a/src/duckstation-qt/controllerbindingwidgets.h +++ b/src/duckstation-qt/controllerbindingwidgets.h @@ -78,7 +78,7 @@ class ControllerMacroWidget : public QWidget Q_OBJECT public: - ControllerMacroWidget(ControllerBindingWidget* parent); + explicit ControllerMacroWidget(ControllerBindingWidget* parent); ~ControllerMacroWidget(); void updateListItem(u32 index); @@ -133,7 +133,7 @@ class ControllerCustomSettingsWidget : public QWidget Q_OBJECT public: - ControllerCustomSettingsWidget(ControllerBindingWidget* parent); + explicit ControllerCustomSettingsWidget(ControllerBindingWidget* parent); ~ControllerCustomSettingsWidget(); void createSettingWidgets(ControllerBindingWidget* parent, QWidget* parent_widget, QGridLayout* layout, diff --git a/src/duckstation-qt/debuggermodels.h b/src/duckstation-qt/debuggermodels.h index 244df41b8..327a7d52a 100644 --- a/src/duckstation-qt/debuggermodels.h +++ b/src/duckstation-qt/debuggermodels.h @@ -20,7 +20,7 @@ class DebuggerCodeModel final : public QAbstractTableModel Q_OBJECT public: - DebuggerCodeModel(QObject* parent = nullptr); + explicit DebuggerCodeModel(QObject* parent = nullptr); ~DebuggerCodeModel() override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; @@ -61,7 +61,7 @@ class DebuggerRegistersModel final : public QAbstractListModel Q_OBJECT public: - DebuggerRegistersModel(QObject* parent = nullptr); + explicit DebuggerRegistersModel(QObject* parent = nullptr); ~DebuggerRegistersModel() override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; @@ -82,7 +82,7 @@ class DebuggerStackModel final : public QAbstractListModel Q_OBJECT public: - DebuggerStackModel(QObject* parent = nullptr); + explicit DebuggerStackModel(QObject* parent = nullptr); ~DebuggerStackModel() override; int rowCount(const QModelIndex& parent = QModelIndex()) const override; @@ -98,7 +98,7 @@ class DebuggerAddBreakpointDialog final : public QDialog Q_OBJECT public: - DebuggerAddBreakpointDialog(QWidget* parent = nullptr); + explicit DebuggerAddBreakpointDialog(QWidget* parent = nullptr); ~DebuggerAddBreakpointDialog() override; u32 getAddress() const { return m_address; } diff --git a/src/duckstation-qt/gamelistrefreshthread.h b/src/duckstation-qt/gamelistrefreshthread.h index 9c148ad67..47b16b3cc 100644 --- a/src/duckstation-qt/gamelistrefreshthread.h +++ b/src/duckstation-qt/gamelistrefreshthread.h @@ -3,7 +3,6 @@ #pragma once -#include #include #include "common/progress_callback.h" @@ -14,7 +13,7 @@ class GameListRefreshThread; class AsyncRefreshProgressCallback : public ProgressCallback { public: - AsyncRefreshProgressCallback(GameListRefreshThread* parent); + explicit AsyncRefreshProgressCallback(GameListRefreshThread* parent); float timeSinceStart() const; @@ -46,7 +45,7 @@ class GameListRefreshThread final : public QThread Q_OBJECT public: - GameListRefreshThread(bool invalidate_cache); + explicit GameListRefreshThread(bool invalidate_cache); ~GameListRefreshThread(); float timeSinceStart() const; @@ -58,7 +57,7 @@ Q_SIGNALS: void refreshComplete(); protected: - void run(); + void run() final; private: AsyncRefreshProgressCallback m_progress; diff --git a/src/duckstation-qt/gamelistwidget.cpp b/src/duckstation-qt/gamelistwidget.cpp index 3972cbfd2..c147cfd37 100644 --- a/src/duckstation-qt/gamelistwidget.cpp +++ b/src/duckstation-qt/gamelistwidget.cpp @@ -1037,7 +1037,7 @@ namespace { class GameListCenterIconStyleDelegate final : public QStyledItemDelegate { public: - GameListCenterIconStyleDelegate(QWidget* parent) : QStyledItemDelegate(parent) {} + explicit GameListCenterIconStyleDelegate(QWidget* parent) : QStyledItemDelegate(parent) {} ~GameListCenterIconStyleDelegate() = default; void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override diff --git a/src/duckstation-qt/gamelistwidget.h b/src/duckstation-qt/gamelistwidget.h index 14adf7e7d..4e69982d3 100644 --- a/src/duckstation-qt/gamelistwidget.h +++ b/src/duckstation-qt/gamelistwidget.h @@ -210,7 +210,7 @@ class GameListWidget final : public QWidget Q_OBJECT public: - GameListWidget(QWidget* parent = nullptr); + explicit GameListWidget(QWidget* parent = nullptr); ~GameListWidget(); ALWAYS_INLINE GameListModel* getModel() const { return m_model; } diff --git a/src/duckstation-qt/inputbindingwidgets.h b/src/duckstation-qt/inputbindingwidgets.h index 8339de5e4..32193505b 100644 --- a/src/duckstation-qt/inputbindingwidgets.h +++ b/src/duckstation-qt/inputbindingwidgets.h @@ -17,7 +17,7 @@ class InputBindingWidget : public QPushButton Q_OBJECT public: - InputBindingWidget(QWidget* parent); + explicit InputBindingWidget(QWidget* parent); InputBindingWidget(QWidget* parent, SettingsInterface* sif, InputBindingInfo::Type bind_type, std::string section_name, std::string key_name); ~InputBindingWidget(); @@ -76,7 +76,7 @@ class InputVibrationBindingWidget : public QPushButton Q_OBJECT public: - InputVibrationBindingWidget(QWidget* parent); + explicit InputVibrationBindingWidget(QWidget* parent); InputVibrationBindingWidget(QWidget* parent, ControllerSettingsWindow* dialog, std::string section_name, std::string key_name); ~InputVibrationBindingWidget(); diff --git a/src/duckstation-qt/isobrowserwindow.h b/src/duckstation-qt/isobrowserwindow.h index b1dabab08..6fdc815d3 100644 --- a/src/duckstation-qt/isobrowserwindow.h +++ b/src/duckstation-qt/isobrowserwindow.h @@ -12,7 +12,7 @@ class ISOBrowserWindow : public QWidget Q_OBJECT public: - ISOBrowserWindow(QWidget* parent = nullptr); + explicit ISOBrowserWindow(QWidget* parent = nullptr); ~ISOBrowserWindow(); static ISOBrowserWindow* createAndOpenFile(QWidget* parent, const QString& path); diff --git a/src/duckstation-qt/qthost.h b/src/duckstation-qt/qthost.h index 93ca7a653..fe8643dcd 100644 --- a/src/duckstation-qt/qthost.h +++ b/src/duckstation-qt/qthost.h @@ -281,7 +281,7 @@ public: using DeviceList = QList; - InputDeviceListModel(QObject* parent = nullptr); + explicit InputDeviceListModel(QObject* parent = nullptr); ~InputDeviceListModel() override; // Safe to access on UI thread. @@ -325,7 +325,7 @@ Q_SIGNALS: void completed(QtAsyncTask* self); private: - QtAsyncTask(WorkCallback callback); + explicit QtAsyncTask(WorkCallback callback); std::variant m_callback; }; diff --git a/src/duckstation-qt/qtprogresscallback.h b/src/duckstation-qt/qtprogresscallback.h index dda0f1a7f..cd417bcd0 100644 --- a/src/duckstation-qt/qtprogresscallback.h +++ b/src/duckstation-qt/qtprogresscallback.h @@ -16,7 +16,7 @@ class QtModalProgressCallback final : public QObject, public ProgressCallback Q_OBJECT public: - QtModalProgressCallback(QWidget* parent_widget, float show_delay = 0.0f); + explicit QtModalProgressCallback(QWidget* parent_widget, float show_delay = 0.0f); ~QtModalProgressCallback(); QProgressDialog& GetDialog() { return m_dialog; } @@ -53,7 +53,7 @@ class QtAsyncProgressThread : public QThread, public ProgressCallback Q_OBJECT public: - QtAsyncProgressThread(QWidget* parent); + explicit QtAsyncProgressThread(QWidget* parent); ~QtAsyncProgressThread(); bool IsCancelled() const override; diff --git a/src/duckstation-qt/selectdiscdialog.h b/src/duckstation-qt/selectdiscdialog.h index 0d3d4a949..9bb2095f9 100644 --- a/src/duckstation-qt/selectdiscdialog.h +++ b/src/duckstation-qt/selectdiscdialog.h @@ -14,7 +14,7 @@ class SelectDiscDialog final : public QDialog Q_OBJECT public: - SelectDiscDialog(const std::string& disc_set_name, QWidget* parent = nullptr); + explicit SelectDiscDialog(const std::string& disc_set_name, QWidget* parent = nullptr); ~SelectDiscDialog(); ALWAYS_INLINE const std::string& getSelectedDiscPath() { return m_selected_path; } diff --git a/src/updater/updater.h b/src/updater/updater.h index e88e28d06..dbd7f472f 100644 --- a/src/updater/updater.h +++ b/src/updater/updater.h @@ -10,7 +10,7 @@ class Updater { public: - Updater(ProgressCallback* progress); + explicit Updater(ProgressCallback* progress); ~Updater(); bool Initialize(std::string staging_directory, std::string destination_directory); diff --git a/src/util/cd_image_cue.cpp b/src/util/cd_image_cue.cpp index 08cbe7715..4e5a90c20 100644 --- a/src/util/cd_image_cue.cpp +++ b/src/util/cd_image_cue.cpp @@ -28,7 +28,7 @@ namespace { class TrackFileInterface { public: - TrackFileInterface(std::string filename); + explicit TrackFileInterface(std::string filename); virtual ~TrackFileInterface(); ALWAYS_INLINE const std::string& GetFileName() const { return m_filename; } diff --git a/src/util/gpu_device.h b/src/util/gpu_device.h index 05f0e6ee6..3af70d20f 100644 --- a/src/util/gpu_device.h +++ b/src/util/gpu_device.h @@ -172,7 +172,7 @@ IMPLEMENT_ENUM_CLASS_BITWISE_OPERATORS(GPUDriverType); class GPUShader { public: - GPUShader(GPUShaderStage stage); + explicit GPUShader(GPUShaderStage stage); virtual ~GPUShader(); static const char* GetStageName(GPUShaderStage stage); diff --git a/src/util/postprocessing.h b/src/util/postprocessing.h index cc20c91a6..05e4696fc 100644 --- a/src/util/postprocessing.h +++ b/src/util/postprocessing.h @@ -114,7 +114,7 @@ void ClearStages(SettingsInterface& si, const char* section); class Chain final { public: - Chain(const char* section); + explicit Chain(const char* section); ~Chain(); ALWAYS_INLINE bool HasStages() const { return !m_stages.empty(); } diff --git a/src/util/postprocessing_shader.h b/src/util/postprocessing_shader.h index e3d1be91d..203dcfb5c 100644 --- a/src/util/postprocessing_shader.h +++ b/src/util/postprocessing_shader.h @@ -27,7 +27,7 @@ class Shader { public: Shader(); - Shader(std::string name); + explicit Shader(std::string name); virtual ~Shader(); ALWAYS_INLINE const std::string& GetName() const { return m_name; } @@ -64,4 +64,4 @@ protected: OptionList m_options; }; -} // namespace PostProcessing \ No newline at end of file +} // namespace PostProcessing