public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait()
@ 2024-06-09  7:19 lewissbaker.opensource at gmail dot com
  2024-06-09 17:02 ` [Bug libstdc++/115402] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: lewissbaker.opensource at gmail dot com @ 2024-06-09  7:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115402

            Bug ID: 115402
           Summary: std::atomic_ref<volatile T> compile-error in
                    compare_exchange_[weak/strong]() and wait()
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lewissbaker.opensource at gmail dot com
  Target Milestone: ---

See https://godbolt.org/z/q4jYvPaah

The following code-snippet fails to compile:

 volatile int vi = 0;
 std::atomic_ref<volatile int> vref(vi);
 int val = vref.load(); // ok
 vref.exchange(val); // ok
 vref.compare_exchange_weak(val, 0); // error
 vref.compare_exchange_strong(val, 0); // error
 vref.wait(0); // error

Fails with error messages like:

.../include/c++/15.0.0/bits/atomic_base.h: In instantiation of 'bool
std::__atomic_ref<_Tp, true, false>::compare_exchange_weak(_Tp&, _Tp,
std::memory_order, std::memory_order) const [with _Tp = volatile int]':
/opt/compiler-explorer/gcc-trunk-20240609/include/c++/15.0.0/bits/atomic_base.h:1674:30:
  required from 'bool std::__atomic_ref<_Tp, true,
false>::compare_exchange_weak(_Tp&, _Tp, std::memory_order) const [with _Tp =
volatile int]'
 1674 |         return compare_exchange_weak(__expected, __desired, __order,
      |                ~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1675 |                                      __cmpexch_failure_order(__order));
      |                                      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:8:31:   required from here
    8 |     vref.compare_exchange_weak(val, 0); // error
      |     ~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
.../include/c++/15.0.0/bits/atomic_base.h:1656:58: error: binding reference of
type 'std::__atomic_impl::_Val<volatile int>&' {aka 'int&'} to 'volatile int'
discards qualifiers
 1656 |         return __atomic_impl::compare_exchange_weak<true>(
      |                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
 1657 |                  _M_ptr, __expected, __desired, __success, __failure);
      |                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../include/c++/15.0.0/bits/atomic_base.h:1119:52: note:   initializing
argument 2 of 'bool std::__atomic_impl::compare_exchange_weak(_Tp*, _Val<_Tp>&,
_Val<_Tp>, std::memory_order, std::memory_order, bool) [with bool _AtomicRef =
true; _Tp = volatile int; _Val<_Tp> = int]'
 1119 |       compare_exchange_weak(_Tp* __ptr, _Val<_Tp>& __expected,
      |                                         ~~~~~~~~~~~^~~~~~~~~~

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

* [Bug libstdc++/115402] std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait()
  2024-06-09  7:19 [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait() lewissbaker.opensource at gmail dot com
@ 2024-06-09 17:02 ` pinskia at gcc dot gnu.org
  2024-06-09 17:05 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-09 17:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115402

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 58393
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=58393&action=edit
Full testcase from compiler explorer link

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

* [Bug libstdc++/115402] std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait()
  2024-06-09  7:19 [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait() lewissbaker.opensource at gmail dot com
  2024-06-09 17:02 ` [Bug libstdc++/115402] " pinskia at gcc dot gnu.org
@ 2024-06-09 17:05 ` pinskia at gcc dot gnu.org
  2024-06-09 17:09 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-09 17:05 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115402

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Note libc++ also fails this. So Does Microsoft's c++ library using MSVC.

So I am not sure if this is a bug or not.

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

* [Bug libstdc++/115402] std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait()
  2024-06-09  7:19 [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait() lewissbaker.opensource at gmail dot com
  2024-06-09 17:02 ` [Bug libstdc++/115402] " pinskia at gcc dot gnu.org
  2024-06-09 17:05 ` pinskia at gcc dot gnu.org
@ 2024-06-09 17:09 ` pinskia at gcc dot gnu.org
  2024-06-09 17:55 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-09 17:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115402

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://cplusplus.github.io/LWG/issue3508

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

* [Bug libstdc++/115402] std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait()
  2024-06-09  7:19 [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait() lewissbaker.opensource at gmail dot com
                   ` (2 preceding siblings ...)
  2024-06-09 17:09 ` pinskia at gcc dot gnu.org
@ 2024-06-09 17:55 ` pinskia at gcc dot gnu.org
  2024-06-10  9:19 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-09 17:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115402

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
https://lists.isocpp.org/lib/2024/06/28451.php

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

* [Bug libstdc++/115402] std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait()
  2024-06-09  7:19 [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait() lewissbaker.opensource at gmail dot com
                   ` (3 preceding siblings ...)
  2024-06-09 17:55 ` pinskia at gcc dot gnu.org
@ 2024-06-10  9:19 ` redi at gcc dot gnu.org
  2024-06-10  9:23 ` redi at gcc dot gnu.org
  2024-06-14 12:52 ` lewissbaker.opensource at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-10  9:19 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115402

--- Comment #5 from Jonathan Wakely <redi at gcc dot gnu.org> ---
And https://cplusplus.github.io/LWG/issue4069 too.

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

* [Bug libstdc++/115402] std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait()
  2024-06-09  7:19 [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait() lewissbaker.opensource at gmail dot com
                   ` (4 preceding siblings ...)
  2024-06-10  9:19 ` redi at gcc dot gnu.org
@ 2024-06-10  9:23 ` redi at gcc dot gnu.org
  2024-06-14 12:52 ` lewissbaker.opensource at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu.org @ 2024-06-10  9:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115402

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
There is a paper being written to address both those issues, but it hasn't been
published yet. It should be P3323 when it's ready.

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

* [Bug libstdc++/115402] std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait()
  2024-06-09  7:19 [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait() lewissbaker.opensource at gmail dot com
                   ` (5 preceding siblings ...)
  2024-06-10  9:23 ` redi at gcc dot gnu.org
@ 2024-06-14 12:52 ` lewissbaker.opensource at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: lewissbaker.opensource at gmail dot com @ 2024-06-14 12:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115402

--- Comment #7 from Lewis Baker <lewissbaker.opensource at gmail dot com> ---
This paper has now been published and is available at:
https://isocpp.org/files/papers/P3323R0.html

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

end of thread, other threads:[~2024-06-14 12:52 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-09  7:19 [Bug libstdc++/115402] New: std::atomic_ref<volatile T> compile-error in compare_exchange_[weak/strong]() and wait() lewissbaker.opensource at gmail dot com
2024-06-09 17:02 ` [Bug libstdc++/115402] " pinskia at gcc dot gnu.org
2024-06-09 17:05 ` pinskia at gcc dot gnu.org
2024-06-09 17:09 ` pinskia at gcc dot gnu.org
2024-06-09 17:55 ` pinskia at gcc dot gnu.org
2024-06-10  9:19 ` redi at gcc dot gnu.org
2024-06-10  9:23 ` redi at gcc dot gnu.org
2024-06-14 12:52 ` lewissbaker.opensource at gmail dot com

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