]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix dangling reference in filesystem::path::filename()
authorJonathan Wakely <jwakely@redhat.com>
Fri, 28 Oct 2022 14:28:09 +0000 (15:28 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Thu, 27 Apr 2023 20:33:56 +0000 (21:33 +0100)
The new -Wdangling-reference warning noticed this.

libstdc++-v3/ChangeLog:

* include/bits/fs_path.h (path::filename()): Fix dangling
reference.

(cherry picked from commit 49237fe6ef677a81eae701f937546210c90b5914)

libstdc++-v3/include/bits/fs_path.h

index 3370bf7161e03c3c2aa4ba089708e34f0b3e7f66..9f0f2bf5d2dcf6ed5bd9dc6870286644d6f4b882 100644 (file)
@@ -1211,9 +1211,9 @@ namespace __detail
       {
        if (_M_pathname.back() == preferred_separator)
          return {};
-       auto& __last = *--end();
-       if (__last._M_type() == _Type::_Filename)
-         return __last;
+       auto __last = --end();
+       if (__last->_M_type() == _Type::_Filename)
+         return *__last;
       }
     return {};
   }