From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id DB180385770F; Thu, 27 Apr 2023 22:01:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB180385770F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682632871; bh=Xmlh5iQVttZqfZD5dukd1NXwH8deIKRnq3zHPGi9LYs=; h=From:To:Subject:Date:From; b=RTjeblQMTGWOlN5vYEjIoRs+FxjcnWCXPXmidqFrxpdber027oWts2bY4dmbPByiU 1AXEZVCYnhU5HpPlAxGU64O2Yy3nxaQNWau91UYiwYN7QZaw+cOSv3ncq1y6IckxSR 70df6DreCWZgIGFbc459PcZxbmG9gWN3KKkiBWOI= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-10658] libstdc++: Fix dangling reference in filesystem::path::filename() X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 3ca17b2b6be8e9bab2ee06636826d92604104475 X-Git-Newrev: 7ced3e5179ee4fa3efaed5201e2c27c9168fdda0 Message-Id: <20230427220111.DB180385770F@sourceware.org> Date: Thu, 27 Apr 2023 22:01:11 +0000 (GMT) List-Id: https://gcc.gnu.org/g:7ced3e5179ee4fa3efaed5201e2c27c9168fdda0 commit r11-10658-g7ced3e5179ee4fa3efaed5201e2c27c9168fdda0 Author: Jonathan Wakely 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 f37e7e8909f..1188e585b14 100644 --- a/libstdc++-v3/include/bits/fs_path.h +++ b/libstdc++-v3/include/bits/fs_path.h @@ -1205,9 +1205,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 {}; }