public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jonathan Wakely <jwakely@redhat.com>
To: Will Hawkins <hawkinsw@obs.cr>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Subject: Re: [PATCH] libstdc++: Add test for LWG Issue 3897
Date: Tue, 5 Dec 2023 15:45:15 +0000	[thread overview]
Message-ID: <CACb0b4mfLUARkRSyzEjOwUB2JCXjHkpOzaB3iXhryn22nZAD0Q@mail.gmail.com> (raw)
In-Reply-To: <20231204164231.784822-1-hawkinsw@obs.cr>

[-- Attachment #1: Type: text/plain, Size: 572 bytes --]

On Mon, 4 Dec 2023 at 16:42, Will Hawkins wrote:
>
> Hello!
>
> Thank you, as always, for the great work that you do on libstdc++. The
> inout_ptr implementation properly handles the issue raised in LWG 3897
> but it seems like having an explicit test might be a good idea.

Thanks, Will, we should definitely have a test for this.

I've tweaked it a bit to avoid leaking the pointer (in case anybody
runs the tests under valgrind or ASan) and to add your new test to the
existing file (to avoid the overhead of a separate test just for this
one check).

See attached ...

[-- Attachment #2: patch.txt --]
[-- Type: text/plain, Size: 1156 bytes --]

commit c02f3696fdb07d1a06c1aa7b035be9a20d65b803
Author: Will Hawkins <hawkinsw@obs.cr>
Date:   Mon Dec 4 20:59:44 2023

    libstdc++: Add test for LWG Issue 3897
    
    Add a test to verify that the implementation of inout_ptr is not
    vulnerable to LWG Issue 3897.
    
    libstdc++-v3/ChangeLog:
    
            * testsuite/20_util/smartptr.adapt/inout_ptr/2.cc: Add check
            for LWG Issue 3897.
    
    Co-authored-by: Jonathan Wakely <jwakely@redhat.com>

diff --git a/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc b/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc
index ca6076209c2..b4a2d95227a 100644
--- a/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc
+++ b/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc
@@ -96,7 +96,22 @@ test_unique_ptr()
   VERIFY( upbd->id == 2 );
 }
 
+void
+test_lwg3897()
+{
+  // Verify that implementation handles LWG Issue 3897
+  auto nuller = [](int** p) {
+    delete *p;
+    *p = nullptr;
+  };
+  int* i = new int{5};
+  nuller(std::inout_ptr(i));
+
+  VERIFY( i == nullptr );
+}
+
 int main()
 {
   test_unique_ptr();
+  test_lwg3897();
 }

  reply	other threads:[~2023-12-05 15:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-04 16:42 Will Hawkins
2023-12-05 15:45 ` Jonathan Wakely [this message]
2023-12-05 15:49   ` Will Hawkins
2023-12-05 16:32     ` Jonathan Wakely

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=CACb0b4mfLUARkRSyzEjOwUB2JCXjHkpOzaB3iXhryn22nZAD0Q@mail.gmail.com \
    --to=jwakely@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=hawkinsw@obs.cr \
    --cc=libstdc++@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).