public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
From: Thomas Rodgers <rodgert@appliantology.com>
To: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org
Cc: trodgers@redhat.com, Thomas Rodgers <rodgert@appliantology.com>
Subject: [PATCH] libstdc++: Fix Wrong param type in :atomic_ref<_Tp*>::wait [PR100889] [PR100889]
Date: Mon,  7 Jun 2021 15:02:07 -0700	[thread overview]
Message-ID: <20210607220207.944400-1-rodgert@appliantology.com> (raw)
In-Reply-To: <CAH6eHdQuPHFGWB8Y86bRbWSOFFimQMxFNLMSO_SRce5NcgZ9WA@mail.gmail.com>

Fixes libstdc++/100889

libstdc++-v3/ChangeLog:

	* include/bits/atomic_base.h (atomic_ref<_Tp*>::wait):
	Change parameter type from _Tp to _Tp*.
	* testsuite/29_atomics/atomic_ref/wait_notify.cc: Extend
	coverage of types tested.
---
 libstdc++-v3/include/bits/atomic_base.h       |  2 +-
 .../29_atomics/atomic_ref/wait_notify.cc      | 38 ++++++++++++-------
 2 files changed, 26 insertions(+), 14 deletions(-)

diff --git a/libstdc++-v3/include/bits/atomic_base.h b/libstdc++-v3/include/bits/atomic_base.h
index 029b8ad65a9..20cf1343c58 100644
--- a/libstdc++-v3/include/bits/atomic_base.h
+++ b/libstdc++-v3/include/bits/atomic_base.h
@@ -1870,7 +1870,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
 #if __cpp_lib_atomic_wait
       _GLIBCXX_ALWAYS_INLINE void
-      wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept
+      wait(_Tp* __old, memory_order __m = memory_order_seq_cst) const noexcept
       { __atomic_impl::wait(_M_ptr, __old, __m); }
 
       // TODO add const volatile overload
diff --git a/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc b/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
index 2fd31304222..2500dddf884 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/wait_notify.cc
@@ -26,22 +26,34 @@
 
 #include <testsuite_hooks.h>
 
+template<typename S>
+  void
+  test (S va, S vb)
+  {
+    S aa{ va };
+    S bb{ vb };
+    std::atomic_ref<S> a{ aa };
+    a.wait(bb);
+    std::thread t([&]
+      {
+        a.store(bb);
+        a.notify_one();
+      });
+    a.wait(aa);
+    t.join();
+  }
+
 int
 main ()
 {
+  test<int>(0, 42);
+  test<long>(0, 42);
+  test<unsigned>(0u, 42u);
+  test<float>(0.0f, 42.0f);
+  test<double>(0.0, 42.0);
+  test<void*>(nullptr, reinterpret_cast<void*>(42));
+
   struct S{ int i; };
-  S aa{ 0 };
-  S bb{ 42 };
-
-  std::atomic_ref<S> a{ aa };
-  VERIFY( a.load().i == aa.i );
-  a.wait(bb);
-  std::thread t([&]
-    {
-      a.store(bb);
-      a.notify_one();
-    });
-  a.wait(aa);
-  t.join();
+  test<S>(S{ 0 }, S{ 42 });
   return 0;
 }
-- 
2.26.2


  parent reply	other threads:[~2021-06-07 22:02 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-04 23:04 [PATCH] PR libstdc++/100889: Fix wrong param type in atomic_ref<_Tp*>::wait Thomas Rodgers
2021-06-04 23:18 ` Jonathan Wakely
2021-06-05  0:44   ` [PATCH] [libstdc++] Fix Wrong param type in :atomic_ref<_Tp*>::wait [PR100889] Thomas Rodgers
2021-06-07 22:02   ` Thomas Rodgers [this message]
2021-06-08  0:28     ` [PATCH] libstdc++: " Thomas Rodgers
2021-06-08 15:44       ` Jonathan Wakely
2021-06-08 23:03         ` Thomas Rodgers
2021-06-09 14:30           ` Christophe Lyon
2021-06-09 14:52             ` Thomas Rodgers
2021-06-09 15:11               ` 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=20210607220207.944400-1-rodgert@appliantology.com \
    --to=rodgert@appliantology.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=libstdc++@gcc.gnu.org \
    --cc=trodgers@redhat.com \
    /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).