Examples of errors detected by the V558 diagnostic

V558. Function returns the pointer/reference to temporary local object.


SeqAn

V558 Function returns the reference to temporary local object: before. iter_concat_virtual.h 277


template <typename TStringSet, typename TSpec>
inline Iter<TStringSet, ConcatVirtual<TSpec> > const &
operator++(Iter<TStringSet, ConcatVirtual<TSpec> > & me, int)
{
    Iter<TStringSet, ConcatVirtual<TSpec> > before = me;
    goNext(me);
    return before;
}

Identical errors can be found in some other places:

  • V558 Function returns the reference to temporary local object: before. iter_concat_virtual.h 310

VirtualDub

V558 Function returns the reference to temporary local object: tmp. VirtualDub vdstl.h 460


vdlist_iterator& operator--(int) {
  vdlist_iterator tmp(*this);
  mp = mp->mListNodePrev;
  return tmp;
}

Geant4 software

V558 Function returns the reference to temporary local object: rprim. G4GMocren g4gmocrenio.cc 131


template <typename T> GMocrenDataPrimitive<T> &
GMocrenDataPrimitive<T>::operator + (
  const GMocrenDataPrimitive<T> & _right)
{
  GMocrenDataPrimitive<T> rprim;
  ....
  return rprim;
}

Clang

V558 Function returns the reference to temporary local object: res. LiveInterval.h 679


SingleLinkedListIterator<T> &operator++(int) {
  SingleLinkedListIterator res = *this;
  ++*this;
  return res;
}


Do you make errors in the code?

Check your code
with PVS-Studio

Static code analysis
for C, C++ and C#

goto PVS-Studio;