On Tue, 1 Feb 2022 at 09:15, Jonathan Wakely <jwakely(a)redhat.com> wrote:
On Mon, 31 Jan 2022 at 22:45, Ron Olson <tachoknight(a)gmail.com> wrote:
>
> Hey all,
>
> I’m troubleshooting an issue and came up with this sample program:
https://pastebin.com/g9S8Z64q to demonstrate the problem.
That's not a valid C++ program, even in C++23 after <stdatomic.h> is added.
For C++23 it needs to be _Atomic(int) because in C++ _Atomic is not a
type qualifier (unlike in C). Clang supports the _Atomic qualifier in
C++ mode, but that's non-standard.
This code is not portable to any compiler except Clang, and is no
longer even portable to Clang when using G++ in C++23 mode.
I suppose we could enable the contents of <stdatomic.h> for the
non-strict -std=gnu++XX modes before C++23, but you'd still need to
adjust your program to use _Atomic(int) instead of _Atomic int.
Why not just write it in proper C++, using std::atomic<int> or the
atomic_int typedef instead?