public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] libstdc++: Add test for LWG Issue 3897
@ 2023-12-04 16:42 Will Hawkins
  2023-12-05 15:45 ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Will Hawkins @ 2023-12-04 16:42 UTC (permalink / raw)
  To: gcc-patches, libstdc++; +Cc: Will Hawkins

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.

I hope that this helps!
Will

-- >8 --

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/3.cc: New test
	for LWG Issue 3897.

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
---
 .../20_util/smartptr.adapt/inout_ptr/3.cc       | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
 create mode 100644 libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/3.cc

diff --git a/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/3.cc b/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/3.cc
new file mode 100644
index 00000000000..f9114dc57b5
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/3.cc
@@ -0,0 +1,17 @@
+// { dg-do run { target c++23 } }
+
+#include <memory>
+#include <testsuite_hooks.h>
+
+// C++23 [inout.ptr.t] Class template inout_ptr_t
+// Verify that implementation handles LWG Issue 3897
+void nuller(int **p) {
+  *p = nullptr;
+}
+
+int main(int, char **) {
+  int *i = new int{5};
+  nuller(std::inout_ptr(i));
+
+  VERIFY(i == nullptr);
+}
-- 
2.41.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libstdc++: Add test for LWG Issue 3897
  2023-12-04 16:42 [PATCH] libstdc++: Add test for LWG Issue 3897 Will Hawkins
@ 2023-12-05 15:45 ` Jonathan Wakely
  2023-12-05 15:49   ` Will Hawkins
  0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2023-12-05 15:45 UTC (permalink / raw)
  To: Will Hawkins; +Cc: gcc-patches, libstdc++

[-- 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();
 }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libstdc++: Add test for LWG Issue 3897
  2023-12-05 15:45 ` Jonathan Wakely
@ 2023-12-05 15:49   ` Will Hawkins
  2023-12-05 16:32     ` Jonathan Wakely
  0 siblings, 1 reply; 4+ messages in thread
From: Will Hawkins @ 2023-12-05 15:49 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: gcc-patches, libstdc++

On Tue, Dec 5, 2023 at 10:46 AM Jonathan Wakely <jwakely@redhat.com> wrote:
>
> 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

Of course ... how could I forget to delete the pointer? I'm a goofball.

> existing file (to avoid the overhead of a separate test just for this
> one check).

Makes perfect sense. I wasn't sure how you typically handle that. I
will know for the future.

>
> See attached ...

Thank you for the feedback! I look forward to the next time I can help!
Will

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] libstdc++: Add test for LWG Issue 3897
  2023-12-05 15:49   ` Will Hawkins
@ 2023-12-05 16:32     ` Jonathan Wakely
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Wakely @ 2023-12-05 16:32 UTC (permalink / raw)
  To: Will Hawkins; +Cc: gcc-patches, libstdc++

On Tue, 5 Dec 2023 at 15:57, Will Hawkins wrote:
>
> On Tue, Dec 5, 2023 at 10:46 AM Jonathan Wakely <jwakely@redhat.com> wrote:
> >
> > 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
>
> Of course ... how could I forget to delete the pointer? I'm a goofball.

:-)

> > existing file (to avoid the overhead of a separate test just for this
> > one check).
>
> Makes perfect sense. I wasn't sure how you typically handle that. I
> will know for the future.

In principle it's better to have one test file per thing we want to
check ... but libstdc++ has a lot of tests, and every one of them
includes the bits/stdc++.h precompiled header which includes the
entire library. And the way dejagnu works, every test runs multiple
compilations, because it preprocesses or compiles various helper files
to check the test conditions. And since I run every test about 20
times (with various combinations of options) it all adds up.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2023-12-05 16:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-04 16:42 [PATCH] libstdc++: Add test for LWG Issue 3897 Will Hawkins
2023-12-05 15:45 ` Jonathan Wakely
2023-12-05 15:49   ` Will Hawkins
2023-12-05 16:32     ` Jonathan Wakely

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).