From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 3709D3830B35; Thu, 24 Nov 2022 16:36:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3709D3830B35 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1669307781; bh=N761ao8eiJ9s/6yzUN5dRm/m8KtEmX9WWSGPTvXf3mY=; h=From:To:Subject:Date:From; b=Lu7Ehe2sCZV310lybjXGp64rGakdiPYCdHYdoluQoB4OJumk+tbiEGlNuAEIdsGr5 DS6jACjIPnUXj/igRHclj9w11MdqAQphHqreR6mnYMZtldP71EBsW1vyqyMqOxDGUw GAfnAIulpOn+rCI1FHPp5kpuGKohps1xiX1Z4S8Q= 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 r12-8934] libstdc++: Fix dangling reference in filesystem::path::filename() X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 825365bec9e9b91173aa98a1ef30472618e6baa0 X-Git-Newrev: 6e3b2c0d5e676e1cba1c27b95dd850e5cc33f9e1 Message-Id: <20221124163621.3709D3830B35@sourceware.org> Date: Thu, 24 Nov 2022 16:36:21 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6e3b2c0d5e676e1cba1c27b95dd850e5cc33f9e1 commit r12-8934-g6e3b2c0d5e676e1cba1c27b95dd850e5cc33f9e1 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 1b4a1b69f37..7a3d0513134 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 {}; }