[gcc r10-11321] libstdc++: Fix dangling reference in filesystem::path::filename()

Jonathan Wakely redi@gcc.gnu.org
Thu Apr 27 23:04:34 GMT 2023


https://gcc.gnu.org/g:cf9eaeaaeec3eb9438b7fc184c493425e8741c88

commit r10-11321-gcf9eaeaaeec3eb9438b7fc184c493425e8741c88
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Fri Oct 28 15:28:09 2022 +0100

    libstdc++: Fix dangling reference in filesystem::path::filename()
    
    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)

Diff:
---
 libstdc++-v3/include/bits/fs_path.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h
index 3370bf7161e..9f0f2bf5d2d 100644
--- a/libstdc++-v3/include/bits/fs_path.h
+++ b/libstdc++-v3/include/bits/fs_path.h
@@ -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 {};
   }


More information about the Libstdc++-cvs mailing list