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 23, 2024
1 parent e4bd4e9 commit a40a5b7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/waveform/waveformwidgetfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ 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 a40a5b7

Please sign in to comment.