From patchwork Tue Nov 21 16:10:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonathan Wakely X-Patchwork-Id: 80495 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E718A386186E for ; Tue, 21 Nov 2023 16:11:30 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 44CC4385B51E for ; Tue, 21 Nov 2023 16:11:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 44CC4385B51E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 44CC4385B51E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700583071; cv=none; b=MeGN/GIeeGpKJ0V032LkfD0YMB1jTpOKypZx+IEqcKDQppdGzdnYPhHsAqGBvoG8hcpoT1O7e63V1cwq/MjNR6W9hjqgT76RtClfuAYb1atLLmC1LSnMRuZndrNwS/jLaCDvtN92KvpUw//yc6aajfFNNdtPRRCkJsTdsfcBkIo= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700583071; c=relaxed/simple; bh=+niLzYFxFBfUVisD8595Mo6fMiuDrQsgJ8cqqM8Djt0=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=EnQNWE/GLw6ZnX+PMzAL8/w1ph3yXZd8oh0aAcGh5BCOUClXN2wxFYHhgqb/dfFgOMbR1R6hXkeAAyymoAaciT2vVsy8tyvUQOv36kFQTQ6oBaoZ4HmIc/s+uNi9eaT7uRhZAM6gC0wDVDvjHtyZdBj6USjtN9gUEvK9qre2a/0= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700583068; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=7KJnHzAxT/en0N2YeIbzF2o5TtfXm9ta9LE24JnncZw=; b=CSTI/xdS6G/83um97rN9XABhR/j9nCwybmJJLOzHBCsE9KOSeFOw6RApn1DubUKn6tjCLX /Eef67bMJUkKzbZ4ZXtff95J/skyXEhn0CUu0NT3fGC9mj/YcUdJ9mQWZJhEieSistrTP0 KlzDPwPx5OtABXPn3nVWnzl6DH0Udbo= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-593-sgNos90mM4OFkXff9k9zeA-1; Tue, 21 Nov 2023 11:11:07 -0500 X-MC-Unique: sgNos90mM4OFkXff9k9zeA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 309E23822561; Tue, 21 Nov 2023 16:11:07 +0000 (UTC) Received: from localhost (unknown [10.42.28.240]) by smtp.corp.redhat.com (Postfix) with ESMTP id A2F0C1C060AE; Tue, 21 Nov 2023 16:11:06 +0000 (UTC) From: Jonathan Wakely To: libstdc++@gcc.gnu.org, gcc-patches@gcc.gnu.org Subject: [committed] libstdc++: Add freestanding feature test macros (P2407R5) Date: Tue, 21 Nov 2023 16:10:27 +0000 Message-ID: <20231121161105.2031146-1-jwakely@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Tested x86_64-linux. Pushed to trunk. -- >8 -- This C++26 change makes several classes "partially freestanding", but we already fully supported them in freestanding mode. All we need to do is define the new feature test macros and add tests for them. libstdc++-v3/ChangeLog: * include/bits/version.def (freestanding_algorithm) (freestanding_array, freestanding_optional) (freestanding_string_view, freestanding_variant): Add. * include/bits/version.h: Regenerate. * include/std/algorithm (__glibcxx_want_freestanding_algorithm): Define. * include/std/array (__glibcxx_want_freestanding_array): Define. * include/std/optional (__glibcxx_want_freestanding_optional): Define. * include/std/string_view (__glibcxx_want_freestanding_string_view): Define. * include/std/variant (__glibcxx_want_freestanding_variant): Define. * testsuite/20_util/optional/version.cc: Add checks for __cpp_lib_freestanding_optional. * testsuite/20_util/variant/version.cc: Add checks for __cpp_lib_freestanding_variant. * testsuite/23_containers/array/tuple_interface/get_neg.cc: Adjust dg-error line numbers. * testsuite/21_strings/basic_string_view/requirements/version.cc: New test. * testsuite/23_containers/array/requirements/version.cc: New test. * testsuite/25_algorithms/fill_n/requirements/version.cc: New test. * testsuite/25_algorithms/swap_ranges/requirements/version.cc: New test. --- libstdc++-v3/include/bits/version.def | 45 +++++++ libstdc++-v3/include/bits/version.h | 127 +++++++++++++----- libstdc++-v3/include/std/algorithm | 1 + libstdc++-v3/include/std/array | 1 + libstdc++-v3/include/std/optional | 1 + libstdc++-v3/include/std/string_view | 3 +- libstdc++-v3/include/std/variant | 1 + .../testsuite/20_util/optional/version.cc | 20 +++ .../testsuite/20_util/variant/version.cc | 20 +++ .../basic_string_view/requirements/version.cc | 19 +++ .../array/requirements/version.cc | 19 +++ .../array/tuple_interface/get_neg.cc | 6 +- .../fill_n/requirements/version.cc | 19 +++ .../swap_ranges/requirements/version.cc | 19 +++ 14 files changed, 261 insertions(+), 40 deletions(-) create mode 100644 libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/version.cc create mode 100644 libstdc++-v3/testsuite/23_containers/array/requirements/version.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/fill_n/requirements/version.cc create mode 100644 libstdc++-v3/testsuite/25_algorithms/swap_ranges/requirements/version.cc diff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def index 59a751da77b..1c49ecea25e 100644 --- a/libstdc++-v3/include/bits/version.def +++ b/libstdc++-v3/include/bits/version.def @@ -1348,15 +1348,60 @@ ftms = { }; }; +ftms = { + name = freestanding_algorithm; + values = { + v = 202311; + // This is a C++26 feature, but we support it in C++23. + cxxmin = 23; + }; +}; + +ftms = { + name = freestanding_array; + values = { + v = 202311; + // This is a C++26 feature, but we support it in C++23. + cxxmin = 23; + }; +}; + ftms = { name = freestanding_expected; values = { v = 202311; cxxmin = 23; + // This is a C++26 feature, but we support it in C++23. extra_cond = "__cpp_lib_expected"; }; }; +ftms = { + name = freestanding_optional; + values = { + v = 202311; + // This is a C++26 feature, but we support it in C++23. + cxxmin = 23; + }; +}; + +ftms = { + name = freestanding_string_view; + values = { + v = 202311; + // This is a C++26 feature, but we support it in C++23. + cxxmin = 23; + }; +}; + +ftms = { + name = freestanding_variant; + values = { + v = 202311; + // This is a C++26 feature, but we support it in C++23. + cxxmin = 23; + }; +}; ftms = { name = invoke_r; diff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h index b3dbfbbcd0d..a61d482c662 100644 --- a/libstdc++-v3/include/bits/version.h +++ b/libstdc++-v3/include/bits/version.h @@ -1631,6 +1631,28 @@ #undef __glibcxx_want_expected // from version.def line 1352 +#if !defined(__cpp_lib_freestanding_algorithm) +# if (__cplusplus >= 202100L) +# define __glibcxx_freestanding_algorithm 202311L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_freestanding_algorithm) +# define __cpp_lib_freestanding_algorithm 202311L +# endif +# endif +#endif /* !defined(__cpp_lib_freestanding_algorithm) && defined(__glibcxx_want_freestanding_algorithm) */ +#undef __glibcxx_want_freestanding_algorithm + +// from version.def line 1361 +#if !defined(__cpp_lib_freestanding_array) +# if (__cplusplus >= 202100L) +# define __glibcxx_freestanding_array 202311L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_freestanding_array) +# define __cpp_lib_freestanding_array 202311L +# endif +# endif +#endif /* !defined(__cpp_lib_freestanding_array) && defined(__glibcxx_want_freestanding_array) */ +#undef __glibcxx_want_freestanding_array + +// from version.def line 1370 #if !defined(__cpp_lib_freestanding_expected) # if (__cplusplus >= 202100L) && (__cpp_lib_expected) # define __glibcxx_freestanding_expected 202311L @@ -1641,7 +1663,40 @@ #endif /* !defined(__cpp_lib_freestanding_expected) && defined(__glibcxx_want_freestanding_expected) */ #undef __glibcxx_want_freestanding_expected -// from version.def line 1362 +// from version.def line 1380 +#if !defined(__cpp_lib_freestanding_optional) +# if (__cplusplus >= 202100L) +# define __glibcxx_freestanding_optional 202311L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_freestanding_optional) +# define __cpp_lib_freestanding_optional 202311L +# endif +# endif +#endif /* !defined(__cpp_lib_freestanding_optional) && defined(__glibcxx_want_freestanding_optional) */ +#undef __glibcxx_want_freestanding_optional + +// from version.def line 1389 +#if !defined(__cpp_lib_freestanding_string_view) +# if (__cplusplus >= 202100L) +# define __glibcxx_freestanding_string_view 202311L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_freestanding_string_view) +# define __cpp_lib_freestanding_string_view 202311L +# endif +# endif +#endif /* !defined(__cpp_lib_freestanding_string_view) && defined(__glibcxx_want_freestanding_string_view) */ +#undef __glibcxx_want_freestanding_string_view + +// from version.def line 1398 +#if !defined(__cpp_lib_freestanding_variant) +# if (__cplusplus >= 202100L) +# define __glibcxx_freestanding_variant 202311L +# if defined(__glibcxx_want_all) || defined(__glibcxx_want_freestanding_variant) +# define __cpp_lib_freestanding_variant 202311L +# endif +# endif +#endif /* !defined(__cpp_lib_freestanding_variant) && defined(__glibcxx_want_freestanding_variant) */ +#undef __glibcxx_want_freestanding_variant + +// from version.def line 1407 #if !defined(__cpp_lib_invoke_r) # if (__cplusplus >= 202100L) # define __glibcxx_invoke_r 202106L diff --git a/libstdc++-v3/include/std/algorithm b/libstdc++-v3/include/std/algorithm index d7fab417111..40aff5018aa 100644 --- a/libstdc++-v3/include/std/algorithm +++ b/libstdc++-v3/include/std/algorithm @@ -65,6 +65,7 @@ #define __glibcxx_want_clamp #define __glibcxx_want_constexpr_algorithms +#define __glibcxx_want_freestanding_algorithm #define __glibcxx_want_parallel_algorithm #define __glibcxx_want_ranges_contains #define __glibcxx_want_ranges_find_last diff --git a/libstdc++-v3/include/std/array b/libstdc++-v3/include/std/array index d34ec5c7c43..ddc15b6788d 100644 --- a/libstdc++-v3/include/std/array +++ b/libstdc++-v3/include/std/array @@ -46,6 +46,7 @@ #include #define __glibcxx_want_array_constexpr +#define __glibcxx_want_freestanding_array #define __glibcxx_want_nonmember_container_access #define __glibcxx_want_to_array #include diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional index a8c97717b72..937486fcc3b 100644 --- a/libstdc++-v3/include/std/optional +++ b/libstdc++-v3/include/std/optional @@ -32,6 +32,7 @@ #pragma GCC system_header +#define __glibcxx_want_freestanding_optional #define __glibcxx_want_optional #include diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index cbb6bb0928f..44d13b403cc 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -36,8 +36,9 @@ #pragma GCC system_header #define __glibcxx_want_constexpr_char_traits -#define __glibcxx_want_string_view #define __glibcxx_want_constexpr_string_view +#define __glibcxx_want_freestanding_string_view +#define __glibcxx_want_string_view #define __glibcxx_want_starts_ends_with #define __glibcxx_want_string_contains #include diff --git a/libstdc++-v3/include/std/variant b/libstdc++-v3/include/std/variant index 7f24e760bb1..36bb37c20e5 100644 --- a/libstdc++-v3/include/std/variant +++ b/libstdc++-v3/include/std/variant @@ -31,6 +31,7 @@ #pragma GCC system_header +#define __glibcxx_want_freestanding_variant #define __glibcxx_want_variant #include diff --git a/libstdc++-v3/testsuite/20_util/optional/version.cc b/libstdc++-v3/testsuite/20_util/optional/version.cc index 7e63d425796..657a3992422 100644 --- a/libstdc++-v3/testsuite/20_util/optional/version.cc +++ b/libstdc++-v3/testsuite/20_util/optional/version.cc @@ -12,3 +12,23 @@ #elif __cplusplus > 202002L && __cpp_lib_optional != 202110L # error "Feature test macro for optional has wrong value for C++23 in " #endif + +#if __cplusplus >= 202302L +#ifndef __cpp_lib_freestanding_optional +# error "Feature test macro for freestanding std::optional is missing in " +#elif __cpp_lib_freestanding_optional < 202311L +# error "Feature test macro for freestanding std::optional has wrong value in " +#endif +#endif + +#undef __cpp_lib_optional +#undef __cpp_lib_freestanding_optional +#include + +#if __cplusplus >= 202302L +#ifndef __cpp_lib_freestanding_optional +# error "Feature test macro for freestanding std::optional is missing in " +#elif __cpp_lib_freestanding_optional < 202311L +# error "Feature test macro for freestanding std::optional has wrong value in " +#endif +#endif diff --git a/libstdc++-v3/testsuite/20_util/variant/version.cc b/libstdc++-v3/testsuite/20_util/variant/version.cc index fd251dd3768..f7985322cc5 100644 --- a/libstdc++-v3/testsuite/20_util/variant/version.cc +++ b/libstdc++-v3/testsuite/20_util/variant/version.cc @@ -10,3 +10,23 @@ #elif __cplusplus >= 202002L && __cpp_lib_variant < 202106L # error "Feature test macro for variant has wrong value for C++20 in " #endif + +#if __cplusplus >= 202302L +#ifndef __cpp_lib_freestanding_variant +# error "Feature test macro for freestanding std::variant is missing in " +#elif __cpp_lib_freestanding_variant < 202311L +# error "Feature test macro for freestanding std::variant has wrong value in " +#endif +#endif + +#undef __cpp_lib_variant +#undef __cpp_lib_freestanding_variant +#include + +#if __cplusplus >= 202302L +#ifndef __cpp_lib_freestanding_variant +# error "Feature test macro for freestanding std::variant is missing in " +#elif __cpp_lib_freestanding_variant < 202311L +# error "Feature test macro for freestanding std::variant has wrong value in " +#endif +#endif diff --git a/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/version.cc b/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/version.cc new file mode 100644 index 00000000000..cc366994783 --- /dev/null +++ b/libstdc++-v3/testsuite/21_strings/basic_string_view/requirements/version.cc @@ -0,0 +1,19 @@ +// { dg-do compile { target c++23 } } +// { dg-add-options no_pch } + +#include + +#ifndef __cpp_lib_freestanding_string_view +# error "Feature test macro for freestanding std::string_view is missing in " +#elif __cpp_lib_freestanding_string_view < 202311L +# error "Feature test macro for freestanding std::string_view has wrong value in " +#endif + +#undef __cpp_lib_freestanding_string_view +#include + +#ifndef __cpp_lib_freestanding_string_view +# error "Feature test macro for freestanding std::string_view is missing in " +#elif __cpp_lib_freestanding_string_view < 202311L +# error "Feature test macro for freestanding std::string_view has wrong value in " +#endif diff --git a/libstdc++-v3/testsuite/23_containers/array/requirements/version.cc b/libstdc++-v3/testsuite/23_containers/array/requirements/version.cc new file mode 100644 index 00000000000..1930805e381 --- /dev/null +++ b/libstdc++-v3/testsuite/23_containers/array/requirements/version.cc @@ -0,0 +1,19 @@ +// { dg-do preprocess { target c++23 } } +// { dg-add-options no_pch } + +#include + +#ifndef __cpp_lib_freestanding_array +# error "Feature test macro for freestanding std::array is missing in " +#elif __cpp_lib_freestanding_array < 202311L +# error "Feature test macro for freestanding std::array has wrong value in " +#endif + +#undef __cpp_lib_freestanding_array +#include + +#ifndef __cpp_lib_freestanding_array +# error "Feature test macro for freestanding std::array is missing in " +#elif __cpp_lib_freestanding_array < 202311L +# error "Feature test macro for freestanding std::array has wrong value in " +#endif diff --git a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc index bf64d298579..e1c92f85b7e 100644 --- a/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/array/tuple_interface/get_neg.cc @@ -26,6 +26,6 @@ int n1 = std::get<1>(a); int n2 = std::get<1>(std::move(a)); int n3 = std::get<1>(ca); -// { dg-error "static assertion failed" "" { target *-*-* } 391 } -// { dg-error "static assertion failed" "" { target *-*-* } 400 } -// { dg-error "static assertion failed" "" { target *-*-* } 409 } +// { dg-error "static assertion failed" "" { target *-*-* } 392 } +// { dg-error "static assertion failed" "" { target *-*-* } 401 } +// { dg-error "static assertion failed" "" { target *-*-* } 410 } diff --git a/libstdc++-v3/testsuite/25_algorithms/fill_n/requirements/version.cc b/libstdc++-v3/testsuite/25_algorithms/fill_n/requirements/version.cc new file mode 100644 index 00000000000..6691aff17cb --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/fill_n/requirements/version.cc @@ -0,0 +1,19 @@ +// { dg-do preprocess { target c++23 } } +// { dg-add-options no_pch } + +#include + +#ifndef __cpp_lib_freestanding_algorithm +# error "Feature test macro for freestanding fill_n is missing in " +#elif __cpp_lib_freestanding_algorithm < 202311L +# error "Feature test macro for freestanding fill_n has wrong value in " +#endif + +#undef __cpp_lib_freestanding_algorithm +#include + +#ifndef __cpp_lib_freestanding_algorithm +# error "Feature test macro for freestanding fill_n is missing in " +#elif __cpp_lib_freestanding_algorithm < 202311L +# error "Feature test macro for freestanding fill_n has wrong value in " +#endif diff --git a/libstdc++-v3/testsuite/25_algorithms/swap_ranges/requirements/version.cc b/libstdc++-v3/testsuite/25_algorithms/swap_ranges/requirements/version.cc new file mode 100644 index 00000000000..2a65e7c51a4 --- /dev/null +++ b/libstdc++-v3/testsuite/25_algorithms/swap_ranges/requirements/version.cc @@ -0,0 +1,19 @@ +// { dg-do preprocess { target c++23 } } +// { dg-add-options no_pch } + +#include + +#ifndef __cpp_lib_freestanding_algorithm +# error "Feature test macro for freestanding swap_ranges is missing in " +#elif __cpp_lib_freestanding_algorithm < 202311L +# error "Feature test macro for freestanding swap_ranges has wrong value in " +#endif + +#undef __cpp_lib_freestanding_algorithm +#include + +#ifndef __cpp_lib_freestanding_algorithm +# error "Feature test macro for freestanding swap_ranges is missing in " +#elif __cpp_lib_freestanding_algorithm < 202311L +# error "Feature test macro for freestanding swap_ranges has wrong value in " +#endif