From 8fb9c3e6a26fa7a212bfe9f7dfd4f069001babab Mon Sep 17 00:00:00 2001 From: Dalton Messmer <33463986+messmerd@users.noreply.github.com> Date: Thu, 28 Sep 2023 20:23:35 -0400 Subject: [PATCH] Fix warnings in Clang build (#6893) * Fix unused variable warning * Fix implicit conversion warning * Fix unused lambda capture in DataFile.cpp * Fix implicit conversions in InstrumentFunctions.cpp * Fix operator precedence bug in Flags.h * Fix unused variable warning in Lv2UridMap.h * Fix unused lambda capture in MixerView.cpp * Fix unused lambda captures in SetupDialog.cpp * Fix unused lambda capture in TrackOperationsWidget.cpp * Fix MSVC build * Fix style * Remove unused member variable in Lv2UridMap.h --- include/Flags.h | 4 ++-- include/Lv2UridMap.h | 2 -- include/MidiEvent.h | 2 +- src/core/DataFile.cpp | 2 +- src/core/DrumSynth.cpp | 7 ++++--- src/core/InstrumentFunctions.cpp | 4 ++-- src/gui/MixerView.cpp | 2 +- src/gui/modals/SetupDialog.cpp | 6 +++--- src/gui/tracks/TrackOperationsWidget.cpp | 2 +- 9 files changed, 15 insertions(+), 16 deletions(-) diff --git a/include/Flags.h b/include/Flags.h index 76106dde660..62a5f8af8ba 100644 --- a/include/Flags.h +++ b/include/Flags.h @@ -48,8 +48,8 @@ class Flags m_value{value} {} - constexpr auto testAll(Flags flags) const -> bool { return *this & flags == flags; } - constexpr auto testAny(Flags flags) const -> bool { return *this & flags != Flags{}; } + constexpr auto testAll(Flags flags) const -> bool { return (*this & flags) == flags; } + constexpr auto testAny(Flags flags) const -> bool { return (*this & flags) != Flags{}; } constexpr auto testFlag(EnumType flag) const -> bool { return static_cast(*this & flag); } constexpr auto operator~() const -> Flags { return Flags{~m_value}; } diff --git a/include/Lv2UridMap.h b/include/Lv2UridMap.h index b8733023e5f..6c22aca3e40 100644 --- a/include/Lv2UridMap.h +++ b/include/Lv2UridMap.h @@ -55,8 +55,6 @@ class UridMap LV2_URID_Map m_mapFeature; LV2_URID_Unmap m_unmapFeature; - LV2_URID m_lastUrid = 0; - public: //! constructor; will set up the features UridMap(); diff --git a/include/MidiEvent.h b/include/MidiEvent.h index 956c33fb389..9a14e427c44 100644 --- a/include/MidiEvent.h +++ b/include/MidiEvent.h @@ -212,7 +212,7 @@ class MidiEvent int32_t m_sysExDataLen; // len of m_sysExData } m_data; - const char* m_sysExData; + [[maybe_unused]] const char* m_sysExData; const void* m_sourcePort; // Stores the source of the MidiEvent: Internal or External (hardware controllers). diff --git a/src/core/DataFile.cpp b/src/core/DataFile.cpp index 8d0a8dca43f..90e81907727 100644 --- a/src/core/DataFile.cpp +++ b/src/core/DataFile.cpp @@ -302,7 +302,7 @@ void DataFile::write( QTextStream & _strm ) bool DataFile::writeFile(const QString& filename, bool withResources) { // Small lambda function for displaying errors - auto showError = [this](QString title, QString body){ + auto showError = [](QString title, QString body){ if (gui::getGUI() != nullptr) { QMessageBox mb; diff --git a/src/core/DrumSynth.cpp b/src/core/DrumSynth.cpp index bc5455c96fc..decc6bfa26d 100644 --- a/src/core/DrumSynth.cpp +++ b/src/core/DrumSynth.cpp @@ -273,7 +273,9 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t *&wave, int channels, sa //generation long Length, tpos=0, tplus, totmp, t, i, j; float x[3] = {0.f, 0.f, 0.f}; - float MasterTune, randmax, randmax2; + float MasterTune; + constexpr float randmax = 1.f / static_cast(RAND_MAX); + constexpr float randmax2 = 2.f / static_cast(RAND_MAX); int MainFilter, HighPass; long NON, NT, TON, DiON, TDroop=0, DStep; @@ -454,7 +456,6 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t *&wave, int channels, sa } //prepare envelopes - randmax = 1.f / RAND_MAX; randmax2 = 2.f * randmax; for (i=1;i<8;i++) { envData[i][NEXTT]=0; envData[i][PNT]=0; } Length = LongestEnv(); @@ -745,4 +746,4 @@ int DrumSynth::GetDSFileSamples(QString dsfile, int16_t *&wave, int channels, sa } -} // namespace lmms \ No newline at end of file +} // namespace lmms diff --git a/src/core/InstrumentFunctions.cpp b/src/core/InstrumentFunctions.cpp index 431afd2fe5c..976363d3d08 100644 --- a/src/core/InstrumentFunctions.cpp +++ b/src/core/InstrumentFunctions.cpp @@ -409,7 +409,7 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n ) // Skip notes randomly if( m_arpSkipModel.value() ) { - if( 100 * ( (float) rand() / (float)( RAND_MAX + 1.0f ) ) < m_arpSkipModel.value() ) + if (100 * static_cast(rand()) / (static_cast(RAND_MAX) + 1.0f) < m_arpSkipModel.value()) { // update counters frames_processed += arp_frames; @@ -425,7 +425,7 @@ void InstrumentFunctionArpeggio::processNote( NotePlayHandle * _n ) if( m_arpMissModel.value() ) { - if( 100 * ( (float) rand() / (float)( RAND_MAX + 1.0f ) ) < m_arpMissModel.value() ) + if (100 * static_cast(rand()) / (static_cast(RAND_MAX) + 1.0f) < m_arpMissModel.value()) { dir = ArpDirection::Random; } diff --git a/src/gui/MixerView.cpp b/src/gui/MixerView.cpp index dff19ca3eb7..018e72c2b20 100644 --- a/src/gui/MixerView.cpp +++ b/src/gui/MixerView.cpp @@ -464,7 +464,7 @@ bool MixerView::confirmRemoval(int index) QString messageTitleRemoveTrack = tr("Confirm removal"); QString askAgainText = tr("Don't ask again"); auto askAgainCheckBox = new QCheckBox(askAgainText, nullptr); - connect(askAgainCheckBox, &QCheckBox::stateChanged, [this](int state) { + connect(askAgainCheckBox, &QCheckBox::stateChanged, [](int state) { // Invert button state, if it's checked we *shouldn't* ask again ConfigManager::inst()->setValue("ui", "mixerchanneldeletionwarning", state ? "0" : "1"); }); diff --git a/src/gui/modals/SetupDialog.cpp b/src/gui/modals/SetupDialog.cpp index 0266285a7a4..09d6ab92c47 100644 --- a/src/gui/modals/SetupDialog.cpp +++ b/src/gui/modals/SetupDialog.cpp @@ -168,8 +168,8 @@ SetupDialog::SetupDialog(ConfigTab tab_to_open) : // Constants for positioning LED check boxes. - const int XDelta = 10; - const int YDelta = 18; + constexpr int XDelta = 10; + constexpr int YDelta = 18; // Main widget. auto main_w = new QWidget(this); @@ -212,7 +212,7 @@ SetupDialog::SetupDialog(ConfigTab tab_to_open) : auto generalControlsLayout = new QVBoxLayout; generalControlsLayout->setSpacing(10); - auto addLedCheckBox = [&XDelta, &YDelta, this](const QString& ledText, TabWidget* tw, int& counter, + auto addLedCheckBox = [&](const QString& ledText, TabWidget* tw, int& counter, bool initialState, const char* toggledSlot, bool showRestartWarning) { auto checkBox = new LedCheckBox(ledText, tw); counter++; diff --git a/src/gui/tracks/TrackOperationsWidget.cpp b/src/gui/tracks/TrackOperationsWidget.cpp index fa1a651f613..31edc4949a0 100644 --- a/src/gui/tracks/TrackOperationsWidget.cpp +++ b/src/gui/tracks/TrackOperationsWidget.cpp @@ -195,7 +195,7 @@ bool TrackOperationsWidget::confirmRemoval() QString messageTitleRemoveTrack = tr("Confirm removal"); QString askAgainText = tr("Don't ask again"); auto askAgainCheckBox = new QCheckBox(askAgainText, nullptr); - connect(askAgainCheckBox, &QCheckBox::stateChanged, [this](int state){ + connect(askAgainCheckBox, &QCheckBox::stateChanged, [](int state){ // Invert button state, if it's checked we *shouldn't* ask again ConfigManager::inst()->setValue("ui", "trackdeletionwarning", state ? "0" : "1"); });