From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 0911A3858037; Tue, 18 Jan 2022 16:31:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0911A3858037 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r12-6688] libstdc++: Define for C++23 X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 58385f6ace42d17da5a73cb9b68ce6173295840f X-Git-Newrev: d7f2a09e98520c4e4927f460ad96803b05a205b1 Message-Id: <20220118163158.0911A3858037@sourceware.org> Date: Tue, 18 Jan 2022 16:31:58 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 18 Jan 2022 16:31:58 -0000 https://gcc.gnu.org/g:d7f2a09e98520c4e4927f460ad96803b05a205b1 commit r12-6688-gd7f2a09e98520c4e4927f460ad96803b05a205b1 Author: Jonathan Wakely Date: Mon Jan 17 14:43:24 2022 +0000 libstdc++: Define for C++23 This adds the C++23 header, as proposed by P0943R6, for compatibility with C code. There are still some ABI differences between atomic_xxx in C and C++ std::atomic_xxx in C++, so this only provides source compatibility, not binary compatibility. libstdc++-v3/ChangeLog: * include/Makefile.am: Install new header. * include/Makefile.in: Regenerate. * include/c_compatibility/stdatomic.h: New file. * testsuite/29_atomics/headers/stdatomic.h/c_compat.cc: New test. Diff: --- libstdc++-v3/include/Makefile.am | 1 + libstdc++-v3/include/Makefile.in | 1 + libstdc++-v3/include/c_compatibility/stdatomic.h | 124 ++++++++++++++++++++ .../29_atomics/headers/stdatomic.h/c_compat.cc | 130 +++++++++++++++++++++ 4 files changed, 256 insertions(+) diff --git a/libstdc++-v3/include/Makefile.am b/libstdc++-v3/include/Makefile.am index d1431926cdd..43f7f9f240d 100644 --- a/libstdc++-v3/include/Makefile.am +++ b/libstdc++-v3/include/Makefile.am @@ -850,6 +850,7 @@ c_compatibility_headers = \ ${c_compatibility_srcdir}/fenv.h \ ${c_compatibility_srcdir}/tgmath.h \ ${c_compatibility_srcdir}/math.h \ + ${c_compatibility_srcdir}/stdatomic.h \ ${c_compatibility_srcdir}/stdlib.h endif diff --git a/libstdc++-v3/include/Makefile.in b/libstdc++-v3/include/Makefile.in index de2a25f5168..88391a44d33 100644 --- a/libstdc++-v3/include/Makefile.in +++ b/libstdc++-v3/include/Makefile.in @@ -1202,6 +1202,7 @@ c_compatibility_builddir = . @GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@ ${c_compatibility_srcdir}/fenv.h \ @GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@ ${c_compatibility_srcdir}/tgmath.h \ @GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@ ${c_compatibility_srcdir}/math.h \ +@GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@ ${c_compatibility_srcdir}/stdatomic.h \ @GLIBCXX_C_HEADERS_C_GLOBAL_TRUE@ ${c_compatibility_srcdir}/stdlib.h @GLIBCXX_C_HEADERS_C_STD_TRUE@c_compatibility_headers = diff --git a/libstdc++-v3/include/c_compatibility/stdatomic.h b/libstdc++-v3/include/c_compatibility/stdatomic.h new file mode 100644 index 00000000000..852574bd87c --- /dev/null +++ b/libstdc++-v3/include/c_compatibility/stdatomic.h @@ -0,0 +1,124 @@ +// C compatibility header -*- C++ -*- + +// Copyright (C) 2022 The GCC developers +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 3, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// Under Section 7 of GPL version 3, you are granted additional +// permissions described in the GCC Runtime Library Exception, version +// 3.1, as published by the Free Software Foundation. + +// You should have received a copy of the GNU General Public License and +// a copy of the GCC Runtime Library Exception along with this program; +// see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +// . + +/** @file include/stdatomic.h + * This is a Standard C++ Library header. + */ + +#ifndef _GLIBCXX_STDATOMIC_H +#define _GLIBCXX_STDATOMIC_H + +#if __cplusplus > 202002L +#include + +#define _Atomic(_Tp) std::atomic<_Tp> + +using std::memory_order; +using std::memory_order_relaxed; +using std::memory_order_consume; +using std::memory_order_acquire; +using std::memory_order_release; +using std::memory_order_acq_rel; +using std::memory_order_seq_cst; +using std::atomic_flag; +using std::atomic_bool; +using std::atomic_char; +using std::atomic_schar; +using std::atomic_uchar; +using std::atomic_short; +using std::atomic_ushort; +using std::atomic_int; +using std::atomic_uint; +using std::atomic_long; +using std::atomic_ulong; +using std::atomic_llong; +using std::atomic_ullong; +#ifdef _GLIBCXX_USE_CHAR8_T +using std::atomic_char8_t; +#endif +using std::atomic_char16_t; +using std::atomic_char32_t; +using std::atomic_wchar_t; +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 +using std::atomic_int8_t; +using std::atomic_uint8_t; +using std::atomic_int16_t; +using std::atomic_uint16_t; +using std::atomic_int32_t; +using std::atomic_uint32_t; +using std::atomic_int64_t; +using std::atomic_uint64_t; +using std::atomic_int_least8_t; +using std::atomic_uint_least8_t; +using std::atomic_int_least16_t; +using std::atomic_uint_least16_t; +using std::atomic_int_least32_t; +using std::atomic_uint_least32_t; +using std::atomic_int_least64_t; +using std::atomic_uint_least64_t; +using std::atomic_int_fast8_t; +using std::atomic_uint_fast8_t; +using std::atomic_int_fast16_t; +using std::atomic_uint_fast16_t; +using std::atomic_int_fast32_t; +using std::atomic_uint_fast32_t; +using std::atomic_int_fast64_t; +using std::atomic_uint_fast64_t; +#endif +using std::atomic_intptr_t; +using std::atomic_uintptr_t; +using std::atomic_size_t; +using std::atomic_ptrdiff_t; +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 +using std::atomic_intmax_t; +using std::atomic_uintmax_t; +#endif +using std::atomic_is_lock_free; +using std::atomic_load; +using std::atomic_load_explicit; +using std::atomic_store; +using std::atomic_store_explicit; +using std::atomic_exchange; +using std::atomic_exchange_explicit; +using std::atomic_compare_exchange_strong; +using std::atomic_compare_exchange_strong_explicit; +using std::atomic_compare_exchange_weak; +using std::atomic_compare_exchange_weak_explicit; +using std::atomic_fetch_add; +using std::atomic_fetch_add_explicit; +using std::atomic_fetch_sub; +using std::atomic_fetch_sub_explicit; +using std::atomic_fetch_or; +using std::atomic_fetch_or_explicit; +using std::atomic_fetch_and; +using std::atomic_fetch_and_explicit; +using std::atomic_flag_test_and_set; +using std::atomic_flag_test_and_set_explicit; +using std::atomic_flag_clear; +using std::atomic_flag_clear_explicit; +using std::atomic_thread_fence; +using std::atomic_signal_fence; + +#endif // C++23 +#endif // _GLIBCXX_STDATOMIC_H diff --git a/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc new file mode 100644 index 00000000000..98c1102a974 --- /dev/null +++ b/libstdc++-v3/testsuite/29_atomics/headers/stdatomic.h/c_compat.cc @@ -0,0 +1,130 @@ +// { dg-options "-std=gnu++23" } +// { dg-do compile { target c++23 } } + +#include + +#ifndef ATOMIC_BOOL_LOCK_FREE +#error ATOMIC_BOOL_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_CHAR_LOCK_FREE +#error ATOMIC_CHAR_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_CHAR16_T_LOCK_FREE +#error ATOMIC_CHAR16_T_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_CHAR32_T_LOCK_FREE +#error ATOMIC_CHAR32_T_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_WCHAR_T_LOCK_FREE +#error ATOMIC_WCHAR_T_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_SHORT_LOCK_FREE +#error ATOMIC_SHORT_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_INT_LOCK_FREE +#error ATOMIC_INT_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_LONG_LOCK_FREE +#error ATOMIC_LONG_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_LLONG_LOCK_FREE +#error ATOMIC_LLONG_LOCK_FREE is not defined in +#endif +#ifndef ATOMIC_POINTER_LOCK_FREE +#error ATOMIC_POINTER_LOCK_FREE is not defined in +#endif + +constexpr const memory_order* orders[] = { + &memory_order_relaxed, &memory_order_consume, &memory_order_acquire, + &memory_order_release, &memory_order_acq_rel, &memory_order_seq_cst +}; + +constexpr atomic_flag flag{}; + +template constexpr bool is_same = false; +template constexpr bool is_same = true; + +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +#ifdef _GLIBCXX_USE_CHAR8_T +static_assert(is_same); +#endif +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); + +#include +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +#endif +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +static_assert(is_same); +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 +static_assert(is_same); +static_assert(is_same); +#endif + +static_assert( requires (::atomic_int* i, int* e) { + ::atomic_is_lock_free(i); + ::atomic_load(i); + ::atomic_load_explicit(i, memory_order_relaxed); + ::atomic_store(i, 2); + ::atomic_store_explicit(i, 3, memory_order_release); + ::atomic_exchange(i, 2); + ::atomic_exchange_explicit(i, 3, memory_order_acq_rel); + ::atomic_compare_exchange_strong(i, e, 2); + ::atomic_compare_exchange_strong_explicit(i, e, 3, + memory_order_acq_rel, + memory_order_relaxed); + ::atomic_compare_exchange_weak(i, e, 2); + ::atomic_compare_exchange_weak_explicit(i, e, 3, + memory_order_acq_rel, + memory_order_relaxed); +} ); + +static_assert( requires (::atomic_flag* f) { + ::atomic_flag_test_and_set(f); + ::atomic_flag_test_and_set_explicit(f, memory_order_relaxed); + ::atomic_flag_clear(f); + ::atomic_flag_clear_explicit(f, memory_order_acq_rel); +} ); + +static_assert( requires (::memory_order o) { + ::atomic_thread_fence(o); + ::atomic_signal_fence(o); +} );