]> 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>
Fri, 28 Oct 2022 23:55:42 +0000 (00:55 +0100)
The new -Wdangling-reference warning noticed this.

libstdc++-v3/ChangeLog:

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

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

index 6e7b366d104ca4e8d7aeb9266afe42e8b89fdcb6..2fc7dcd98c9514e194a66da4fd77963ad617b4e1 100644 (file)
@@ -1262,9 +1262,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 {};
   }