[committed] libstdc++: Add freestanding feature test macros (P2407R5)

Message ID 20231121161105.2031146-1-jwakely@redhat.com
State Committed
Headers
Series [committed] libstdc++: Add freestanding feature test macros (P2407R5) |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Jonathan Wakely Nov. 21, 2023, 4:10 p.m. UTC
  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
  

Patch

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 <debug/assertions.h>
 
 #define __glibcxx_want_array_constexpr
+#define __glibcxx_want_freestanding_array
 #define __glibcxx_want_nonmember_container_access
 #define __glibcxx_want_to_array
 #include <bits/version.h>
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 <bits/version.h>
 
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 <bits/version.h>
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 <bits/version.h>
 
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 <version>"
 #endif
+
+#if __cplusplus >= 202302L
+#ifndef __cpp_lib_freestanding_optional
+# error "Feature test macro for freestanding std::optional is missing in <version>"
+#elif __cpp_lib_freestanding_optional < 202311L
+# error "Feature test macro for freestanding std::optional has wrong value in <version>"
+#endif
+#endif
+
+#undef __cpp_lib_optional
+#undef __cpp_lib_freestanding_optional
+#include <optional>
+
+#if __cplusplus >= 202302L
+#ifndef __cpp_lib_freestanding_optional
+# error "Feature test macro for freestanding std::optional is missing in <optional>"
+#elif __cpp_lib_freestanding_optional < 202311L
+# error "Feature test macro for freestanding std::optional has wrong value in <optional>"
+#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 <version>"
 #endif
+
+#if __cplusplus >= 202302L
+#ifndef __cpp_lib_freestanding_variant
+# error "Feature test macro for freestanding std::variant is missing in <version>"
+#elif __cpp_lib_freestanding_variant < 202311L
+# error "Feature test macro for freestanding std::variant has wrong value in <version>"
+#endif
+#endif
+
+#undef __cpp_lib_variant
+#undef __cpp_lib_freestanding_variant
+#include <variant>
+
+#if __cplusplus >= 202302L
+#ifndef __cpp_lib_freestanding_variant
+# error "Feature test macro for freestanding std::variant is missing in <variant>"
+#elif __cpp_lib_freestanding_variant < 202311L
+# error "Feature test macro for freestanding std::variant has wrong value in <variant>"
+#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 <string_view>
+
+#ifndef __cpp_lib_freestanding_string_view
+# error "Feature test macro for freestanding std::string_view is missing in <string_view>"
+#elif __cpp_lib_freestanding_string_view < 202311L
+# error "Feature test macro for freestanding std::string_view has wrong value in <string_view>"
+#endif
+
+#undef __cpp_lib_freestanding_string_view
+#include <version>
+
+#ifndef __cpp_lib_freestanding_string_view
+# error "Feature test macro for freestanding std::string_view is missing in <version>"
+#elif __cpp_lib_freestanding_string_view < 202311L
+# error "Feature test macro for freestanding std::string_view has wrong value in <version>"
+#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 <array>
+
+#ifndef __cpp_lib_freestanding_array
+# error "Feature test macro for freestanding std::array is missing in <array>"
+#elif __cpp_lib_freestanding_array < 202311L
+# error "Feature test macro for freestanding std::array has wrong value in <array>"
+#endif
+
+#undef __cpp_lib_freestanding_array
+#include <version>
+
+#ifndef __cpp_lib_freestanding_array
+# error "Feature test macro for freestanding std::array is missing in <version>"
+#elif __cpp_lib_freestanding_array < 202311L
+# error "Feature test macro for freestanding std::array has wrong value in <version>"
+#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 <algorithm>
+
+#ifndef __cpp_lib_freestanding_algorithm
+# error "Feature test macro for freestanding fill_n is missing in <algorithm>"
+#elif __cpp_lib_freestanding_algorithm < 202311L
+# error "Feature test macro for freestanding fill_n has wrong value in <algorithm>"
+#endif
+
+#undef __cpp_lib_freestanding_algorithm
+#include <version>
+
+#ifndef __cpp_lib_freestanding_algorithm
+# error "Feature test macro for freestanding fill_n is missing in <version>"
+#elif __cpp_lib_freestanding_algorithm < 202311L
+# error "Feature test macro for freestanding fill_n has wrong value in <version>"
+#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 <algorithm>
+
+#ifndef __cpp_lib_freestanding_algorithm
+# error "Feature test macro for freestanding swap_ranges is missing in <algorithm>"
+#elif __cpp_lib_freestanding_algorithm < 202311L
+# error "Feature test macro for freestanding swap_ranges has wrong value in <algorithm>"
+#endif
+
+#undef __cpp_lib_freestanding_algorithm
+#include <version>
+
+#ifndef __cpp_lib_freestanding_algorithm
+# error "Feature test macro for freestanding swap_ranges is missing in <version>"
+#elif __cpp_lib_freestanding_algorithm < 202311L
+# error "Feature test macro for freestanding swap_ranges has wrong value in <version>"
+#endif