From: Jonathan Wakely Date: Fri, 28 Oct 2022 14:28:09 +0000 (+0100) Subject: libstdc++: Fix dangling reference in filesystem::path::filename() X-Git-Tag: release-12.2.mpacbti-rel1~260 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e3b2c0d5e676e1cba1c27b95dd850e5cc33f9e1;p=thirdparty%2Fgcc.git 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 --git a/libstdc++-v3/include/bits/fs_path.h b/libstdc++-v3/include/bits/fs_path.h index 1b4a1b69f377..7a3d05131347 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -1288,9 +1288,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 {}; }