[committed] libstdc++: Fix dangling reference in filesystem::path::filename()

Message ID 20221028235632.194108-1-jwakely@redhat.com
State Repeat Merge
Headers
Series [committed] libstdc++: Fix dangling reference in filesystem::path::filename() |

Checks

Context Check Description
snail/gcc-patch-check warning Git am fail log

Commit Message

Jonathan Wakely Oct. 28, 2022, 11:56 p.m. UTC
  Tested powerpc64le-linux. Pushed to trunk. Worth backporting too.

-- >8 --

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 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
  

Patch

diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index 6e7b366d104..2fc7dcd98c9 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -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 {};
   }