]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Add test for LWG Issue 3897
authorWill Hawkins <hawkinsw@obs.cr>
Mon, 4 Dec 2023 20:59:44 +0000 (20:59 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 5 Dec 2023 16:40:43 +0000 (16:40 +0000)
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>
libstdc++-v3/testsuite/20_util/smartptr.adapt/inout_ptr/2.cc

index ca6076209c2ff02e36d06df135a6349e2aaf40c2..b4a2d95227a1c39f84c3a387f6ffa6d19a59d5b4 100644 (file)
@@ -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();
 }