Skip to content

Commit

Permalink
fix(dlgprefwaveform): Fix -Wdangling-reference on GCC 14.1.1
Browse files Browse the repository at this point in the history
Fixes the following warning:

    src/preferences/dialog/dlgprefwaveform.cpp: In member function ‘void DlgPrefWaveform::updateWaveformAcceleration(WaveformWidgetType::Type, WaveformWidgetBackend)’:
    src/preferences/dialog/dlgprefwaveform.cpp:462:21: error: possibly dangling reference to a temporary [-Werror=dangling-reference]
      462 |         const auto& handle = factory->getAvailableTypes()[handleIdx];
          |                     ^~~~~~
    src/preferences/dialog/dlgprefwaveform.cpp:462:68: note: the temporary was destroyed at the end of the full expression ‘WaveformWidgetFactory::getAvailableTypes() const().QList<WaveformWidgetAbstractHandle>::operator[](((qsizetype)handleIdx))’
      462 |         const auto& handle = factory->getAvailableTypes()[handleIdx];
          |                                                                    ^
    cc1plus: all warnings being treated as errors

I made `getAvailableTypes()` return a const reference to show that the
underlying `QVector` does not get dropped. Alternatively, we'd have to
save the return value in a temporary local variable to fix the warning.
  • Loading branch information
Holzhaus committed Jul 24, 2024
1 parent af0e972 commit 40f77e3
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/waveform/waveformwidgetfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ class WaveformWidgetFactory : public QObject, public Singleton<WaveformWidgetFac
void setOverviewNormalized(bool normalize);
int isOverviewNormalized() const { return m_overviewNormalized;}

const QVector<WaveformWidgetAbstractHandle> getAvailableTypes() const { return m_waveformWidgetHandles;}
const QVector<WaveformWidgetAbstractHandle>& getAvailableTypes() const {
return m_waveformWidgetHandles;
}
void getAvailableVSyncTypes(QList<QPair<int, QString>>* list);
void destroyWidgets();

Expand Down

0 comments on commit 40f77e3

Please sign in to comment.