On 09/12/24 13:22 +0100, Giuseppe D'Angelo wrote:
Hello,
Finally, this commit deprecates is_trivial and is_trivial_v in C++26.
Looks good, thanks. I'll apply this whole series.
Thanks,
--
Giuseppe D'Angelo
From 976ad3ec85cdd6fbd6eea7495077ef5b602cf088 Mon Sep 17 00:00:00 2001
From: Giuseppe D'Angelo <giuseppe.dang...@kdab.com>
Date: Mon, 9 Dec 2024 01:28:08 +0100
Subject: [PATCH 6/6] libstdc++: deprecate is_trivial (P3247R2)
This actually implements P3247R2 by deprecating the is_trivial type
trait.
libstdc++-v3/ChangeLog:
* include/std/type_traits: Deprecate is_trivial and
is_trivial_v.
* testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc:
Amend the test to suppress the deprecation warning.
* testsuite/20_util/is_trivial/requirements/typedefs.cc:
Likewise.
* testsuite/20_util/is_trivial/value.cc: Likewise.
* testsuite/20_util/variable_templates_for_traits.cc: Likewise.
* testsuite/experimental/type_traits/value.cc: Likewise.
* testsuite/18_support/max_align_t/requirements/2.cc: Update the
test with P3247R2's new wording.
Signed-off-by: Giuseppe D'Angelo <giuseppe.dang...@kdab.com>
---
libstdc++-v3/include/std/type_traits | 13 +++++++++++--
.../18_support/max_align_t/requirements/2.cc | 4 ++++
.../requirements/explicit_instantiation.cc | 3 +++
.../20_util/is_trivial/requirements/typedefs.cc | 3 +++
libstdc++-v3/testsuite/20_util/is_trivial/value.cc | 3 +++
.../20_util/variable_templates_for_traits.cc | 4 ++++
.../testsuite/experimental/type_traits/value.cc | 4 ++++
7 files changed, 32 insertions(+), 2 deletions(-)
diff --git a/libstdc++-v3/include/std/type_traits
b/libstdc++-v3/include/std/type_traits
index c650094f8c5..ae410f05a9c 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -885,9 +885,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
: public true_type { };
#endif
- /// is_trivial
+ /** is_trivial
+ * @deprecated Deprecated in C++26.
+ * Use a combination of one or more more specialized type traits instead,
+ * such as `is_trivially_default_constructible`,
+ * `is_trivially_copy_constructible`, `is_trivially_copy_assignable`,
+ * etc., depending on the exact check(s) needed.
+ */
template<typename _Tp>
- struct is_trivial
+ struct
+ _GLIBCXX26_DEPRECATED_SUGGEST("is_trivially_default_constructible &&
is_trivially_copyable")
+ is_trivial
: public __bool_constant<__is_trivial(_Tp)>
{
static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
@@ -3518,6 +3526,7 @@ template <typename _Tp>
#endif
template <typename _Tp>
+ _GLIBCXX26_DEPRECATED_SUGGEST("is_trivially_default_constructible_v &&
is_trivially_copyable_v")
inline constexpr bool is_trivial_v = __is_trivial(_Tp);
template <typename _Tp>
inline constexpr bool is_trivially_copyable_v = __is_trivially_copyable(_Tp);
diff --git a/libstdc++-v3/testsuite/18_support/max_align_t/requirements/2.cc
b/libstdc++-v3/testsuite/18_support/max_align_t/requirements/2.cc
index b61a4b2b35d..c496ad67425 100644
--- a/libstdc++-v3/testsuite/18_support/max_align_t/requirements/2.cc
+++ b/libstdc++-v3/testsuite/18_support/max_align_t/requirements/2.cc
@@ -24,4 +24,8 @@
static_assert (std::is_pod<std::max_align_t>::value, "");
#endif
static_assert (std::is_standard_layout<std::max_align_t>::value, "");
+static_assert (std::is_trivially_copyable<std::max_align_t>::value, "");
+static_assert (std::is_trivially_default_constructible<std::max_align_t>::value,
"");
+#if __cplusplus <= 202302L
static_assert (std::is_trivial<std::max_align_t>::value, "");
+#endif
diff --git
a/libstdc++-v3/testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc
b/libstdc++-v3/testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc
index bace0ed0058..e66b7d4b27d 100644
---
a/libstdc++-v3/testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc
+++
b/libstdc++-v3/testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc
@@ -25,5 +25,8 @@
namespace std
{
typedef short test_type;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
template struct is_trivial<test_type>;
+#pragma GCC diagnostic pop
}
diff --git a/libstdc++-v3/testsuite/20_util/is_trivial/requirements/typedefs.cc
b/libstdc++-v3/testsuite/20_util/is_trivial/requirements/typedefs.cc
index 218246ca3be..4e86fbafbde 100644
--- a/libstdc++-v3/testsuite/20_util/is_trivial/requirements/typedefs.cc
+++ b/libstdc++-v3/testsuite/20_util/is_trivial/requirements/typedefs.cc
@@ -26,7 +26,10 @@
void test01()
{
// Check for required typedefs
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
typedef std::is_trivial<int> test_type;
+#pragma GCC diagnostic pop
typedef test_type::value_type value_type;
typedef test_type::type type;
typedef test_type::type::value_type type_value_type;
diff --git a/libstdc++-v3/testsuite/20_util/is_trivial/value.cc
b/libstdc++-v3/testsuite/20_util/is_trivial/value.cc
index 22acec26b2e..195f44dcb0c 100644
--- a/libstdc++-v3/testsuite/20_util/is_trivial/value.cc
+++ b/libstdc++-v3/testsuite/20_util/is_trivial/value.cc
@@ -27,9 +27,12 @@ void test01()
using std::is_trivial;
using namespace __gnu_test;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
static_assert(test_category<is_trivial, TType>(true), "");
static_assert(test_category<is_trivial, PODType>(true), "");
static_assert(test_category<is_trivial, NType>(false), "");
static_assert(test_category<is_trivial, SLType>(false), "");
+#pragma GCC diagnostic pop
}
diff --git a/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
b/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
index 5a1b777078b..2984a0e67af 100644
--- a/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
+++ b/libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
@@ -129,8 +129,12 @@ private:
int i2;
};
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+// Deprecated in C++26
static_assert(is_trivial_v<int> && is_trivial<int>::value, "");
static_assert(!is_trivial_v<NType> && !is_trivial<NType>::value, "");
+#pragma GCC diagnostic pop
static_assert(is_trivially_copyable_v<int>
&& is_trivially_copyable<int>::value, "");
diff --git a/libstdc++-v3/testsuite/experimental/type_traits/value.cc
b/libstdc++-v3/testsuite/experimental/type_traits/value.cc
index b33b0150ceb..6dfc835d78a 100644
--- a/libstdc++-v3/testsuite/experimental/type_traits/value.cc
+++ b/libstdc++-v3/testsuite/experimental/type_traits/value.cc
@@ -196,8 +196,12 @@ private:
int i2;
};
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
+// Deprecated in C++26
static_assert(is_trivial_v<int> && is_trivial<int>::value, "");
static_assert(!is_trivial_v<NType> && !is_trivial<NType>::value, "");
+#pragma GCC diagnostic pop
static_assert(is_trivially_copyable_v<int>
&& is_trivially_copyable<int>::value, "");
--
2.34.1