Bug 100889 - Wrong param type for std::atomic_ref<_Tp*>::wait
Summary: Wrong param type for std::atomic_ref<_Tp*>::wait
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Thomas Rodgers
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2021-06-03 05:59 UTC by Richard Li
Modified: 2021-06-08 23:11 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-06-03 00:00:00


Attachments
Proposed patch (309 bytes, patch)
2021-06-03 06:02 UTC, Richard Li
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Li 2021-06-03 05:59:42 UTC
/tmp % cat a.cpp
#include <atomic>
void* p;
void foo() { std::atomic_ref(p).store(nullptr); }

/tmp % g++-11.1.0 -c -std=gnu++20 a.cpp
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/g++-v11/atomic:41,
                 from a.cpp:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/g++-v11/bits/atomic_base.h: In instantiation of 'struct std::__atomic_ref<void*, false, false>':
/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/g++-v11/atomic:1618:12:   required from 'struct std::atomic_ref<void*>'
a.cpp:3:31:   required from here
/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/g++-v11/bits/atomic_base.h:1873:7: error: invalid parameter type 'void'
 1873 |       wait(_Tp __old, memory_order __m = memory_order_seq_cst) const noexcept
      |       ^~~~
/usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0/include/g++-v11/bits/atomic_base.h:1873:7: error: in declaration 'void std::__atomic_ref<_Tp*, false, false>::wait(_Tp, std::memory_order) const'


Apparently, the first param of std::atomic<_Tp*>::wait should be _Tp* instead of _Tp.

It appears this bug has existed since GCC 11, when __cpp_lib_atomic_wait was implemented.
Comment 1 Richard Li 2021-06-03 06:02:01 UTC
Created attachment 50917 [details]
Proposed patch

This patch fixes the problem.
Comment 2 GCC Commits 2021-06-08 23:01:17 UTC
The master branch has been updated by Thomas Rodgers <rodgertq@gcc.gnu.org>:

https://gcc.gnu.org/g:25e5ecdf82b49977e86bfaded236fb34af2705ed

commit r12-1312-g25e5ecdf82b49977e86bfaded236fb34af2705ed
Author: Thomas Rodgers <rodgert@appliantology.com>
Date:   Tue Jun 8 15:51:53 2021 -0700

    libstdc++: Fix Wrong param type in :atomic_ref<_Tp*>::wait [PR100889]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/100889
            * 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.
Comment 3 GCC Commits 2021-06-08 23:02:33 UTC
The releases/gcc-11 branch has been updated by Thomas Rodgers <rodgertq@gcc.gnu.org>:

https://gcc.gnu.org/g:d7462945387b33744f665d1aa33ba1cec79c03b0

commit r11-8528-gd7462945387b33744f665d1aa33ba1cec79c03b0
Author: Thomas Rodgers <rodgert@appliantology.com>
Date:   Tue Jun 8 15:51:53 2021 -0700

    libstdc++: Fix Wrong param type in :atomic_ref<_Tp*>::wait [PR100889]
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/100889
            * 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.
    
    (cherry picked from commit 25e5ecdf82b49977e86bfaded236fb34af2705ed)
Comment 4 Thomas Rodgers 2021-06-08 23:11:51 UTC
Fixed in master, backported to releases/gcc-11