https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100147

            Bug ID: 100147
           Summary: libstdc++-v3/include/bits/gslice.h:170: missing check
                    for assignment to self ?
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

Static analyser cppcheck says:

libstdc++-v3/include/bits/gslice.h:170:11: warning: 'operator=' should check
for assignment to self to avoid problems with dynamic memory.
[operatorEqToSelf]

Source code is

  inline gslice&
  gslice::operator=(const gslice& __g)
  {
    if (__g._M_index)
      __g._M_index->_M_increment_use();
    if (_M_index && _M_index->_M_decrement_use() == 0)
      delete _M_index;
    _M_index = __g._M_index;
    return *this;
  }

It certainly would be standard C++ practice to make the check for assignment
to self. 

Perhaps there is a good reason why it isn't done here.
If so, there may be some value in documenting why.

Reply via email to