public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-8934] libstdc++: Fix dangling reference in filesystem::path::filename()
Date: Thu, 24 Nov 2022 16:36:21 +0000 (GMT)	[thread overview]
Message-ID: <20221124163621.3709D3830B35@sourceware.org> (raw)

https://gcc.gnu.org/g:6e3b2c0d5e676e1cba1c27b95dd850e5cc33f9e1

commit r12-8934-g6e3b2c0d5e676e1cba1c27b95dd850e5cc33f9e1
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 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 {};
   }

                 reply	other threads:[~2022-11-24 16:36 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221124163621.3709D3830B35@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).