PR libstdc++/100889: Fix wrong param type in atomic_ref<_Tp*>::wait

Message ID 20210604230434.910594-1-rodgert@appliantology.com
State New
Headers show
Series
  • PR libstdc++/100889: Fix wrong param type in atomic_ref<_Tp*>::wait
Related show

Commit Message

Thomas Rodgers June 4, 2021, 11:04 p.m.
Fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=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/deduction.cc: Add
	reproducer case from PR.
---
 libstdc++-v3/include/bits/atomic_base.h                   | 2 +-
 libstdc++-v3/testsuite/29_atomics/atomic_ref/deduction.cc | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

-- 
2.26.2

Comments

Jonathan Wakely via Gcc-patches June 4, 2021, 11:18 p.m. | #1
On Sat, 5 Jun 2021, 00:05 Thomas Rodgers, <rodgert@appliantology.com> wrote:

> Fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=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/deduction.cc: Add

>         reproducer case from PR.

>


That file is testing CTAD, there should be a better place to add this.



---
>  libstdc++-v3/include/bits/atomic_base.h                   | 2 +-

>  libstdc++-v3/testsuite/29_atomics/atomic_ref/deduction.cc | 1 +

>  2 files changed, 2 insertions(+), 1 deletion(-)

>

> 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/deduction.cc

> b/libstdc++-v3/testsuite/29_atomics/atomic_ref/deduction.cc

> index 86395b0c2b0..ed46b430f7c 100644

> --- a/libstdc++-v3/testsuite/29_atomics/atomic_ref/deduction.cc

> +++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/deduction.cc

> @@ -34,6 +34,7 @@ test01()

>    int* p = &i;

>    std::atomic_ref a2(p);

>    static_assert(std::is_same_v<decltype(a2), std::atomic_ref<int*>>);

> +  a2.store(nullptr);

>

>    struct X { } x;

>    std::atomic_ref a3(x);

> --

> 2.26.2

>

>

Patch

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/deduction.cc b/libstdc++-v3/testsuite/29_atomics/atomic_ref/deduction.cc
index 86395b0c2b0..ed46b430f7c 100644
--- a/libstdc++-v3/testsuite/29_atomics/atomic_ref/deduction.cc
+++ b/libstdc++-v3/testsuite/29_atomics/atomic_ref/deduction.cc
@@ -34,6 +34,7 @@  test01()
   int* p = &i;
   std::atomic_ref a2(p);
   static_assert(std::is_same_v<decltype(a2), std::atomic_ref<int*>>);
+  a2.store(nullptr);
 
   struct X { } x;
   std::atomic_ref a3(x);