From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 56536385697F; Thu, 27 Apr 2023 23:04:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 56536385697F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682636674; bh=F/Le12ZMzyeOUbjs5KReQ4t1noif4kvokNw21AaJeSM=; h=From:To:Subject:Date:From; b=npnFKJlnMdHBP6bJMeyqT8CVkcG50obGjPrqmP34KWUtqaxvdiU3Mao20ajXIkZaE 9z2Dgfp64hFAvj3LHWSaOQZYOyz/LsbjGdGOvLx45z+UFzlz+6OQ5PhwLSFga2Ju01 Ux8bAlVb4Y3CpjFnbFBheuBuyB2zAmC5Ts5HeywM= 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 r10-11321] libstdc++: Fix dangling reference in filesystem::path::filename() X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: cc75195ee8811d6c48f05727c170916c0adc227b X-Git-Newrev: cf9eaeaaeec3eb9438b7fc184c493425e8741c88 Message-Id: <20230427230434.56536385697F@sourceware.org> Date: Thu, 27 Apr 2023 23:04:34 +0000 (GMT) List-Id: https://gcc.gnu.org/g:cf9eaeaaeec3eb9438b7fc184c493425e8741c88 commit r10-11321-gcf9eaeaaeec3eb9438b7fc184c493425e8741c88 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 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 {}; }