https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120029
--- Comment #4 from Haoxiang Yu <yhx12243 at gmail dot com> --- (In reply to Jonathan Wakely from comment #3) > The simplest fix is just: > > --- a/libstdc++-v3/src/c++17/fs_path.cc > +++ b/libstdc++-v3/src/c++17/fs_path.cc > @@ -880,6 +880,9 @@ path::operator+=(const path& p) > return *this; > } > > + if (&p == this) [[unlikely]] > + return *this += p.native(); > + > #if _GLIBCXX_FILESYSTEM_IS_WINDOWS > if (_M_type() == _Type::_Root_name > || (_M_type() == _Type::_Filename && _M_pathname.size() == 1)) Yes it is indeed the simplest way to resolve. The main question is that is it worthy to handle these case in a non-copy way.