]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: deprecate is_trivial for C++26 (P3247R2)
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Mon, 9 Dec 2024 00:28:08 +0000 (01:28 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Tue, 10 Dec 2024 00:50:26 +0000 (00:50 +0000)
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.
* include/experimental/type_traits: Suppress the deprecation
warning.
* 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.dangelo@kdab.com>
libstdc++-v3/include/experimental/type_traits
libstdc++-v3/include/std/type_traits
libstdc++-v3/testsuite/18_support/max_align_t/requirements/2.cc
libstdc++-v3/testsuite/20_util/is_trivial/requirements/explicit_instantiation.cc
libstdc++-v3/testsuite/20_util/is_trivial/requirements/typedefs.cc
libstdc++-v3/testsuite/20_util/is_trivial/value.cc
libstdc++-v3/testsuite/20_util/variable_templates_for_traits.cc
libstdc++-v3/testsuite/experimental/type_traits/value.cc

index 25bb217442072cc9d3090d803b05adf60bc6f3c0..917ac2d34053a8d6ba2a99dfea877d61863bba66 100644 (file)
@@ -121,8 +121,11 @@ template <typename _Tp>
   constexpr bool is_const_v = is_const<_Tp>::value;
 template <typename _Tp>
   constexpr bool is_volatile_v = is_volatile<_Tp>::value;
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 template <typename _Tp>
   constexpr bool is_trivial_v = is_trivial<_Tp>::value;
+#pragma GCC diagnostic pop
 template <typename _Tp>
   constexpr bool is_trivially_copyable_v = is_trivially_copyable<_Tp>::value;
 template <typename _Tp>
index c650094f8c52aa8fce97f5cd76da7e30afa4358c..ae410f05a9cd41dfab554c20f41e5015d602798a 100644 (file)
@@ -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);
index b61a4b2b35d40c650aee63eef2172b75f8378286..c496ad674254f7980486e7af668e11a2143d8118 100644 (file)
@@ -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
index bace0ed00583ad3c3a84cb6e3cb0e5c565221485..e66b7d4b27d9dbf875ae119ea4c4ab2f80f634f6 100644 (file)
@@ -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
 }
index 218246ca3be2058adda9a3514846892097953dec..4e86fbafbded5a5af0133ec94e09fa3b28dd1130 100644 (file)
 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;
index 22acec26b2efadbb7f7e8bd637ec2e2f57067902..195f44dcb0c6a0a1805b2f580764a870c3b790f2 100644 (file)
@@ -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
 }
index 5a1b777078bb3b63f9b5173b7c811967a4d2ae21..2984a0e67af084b5589cf29d2515901c9b90b0ca 100644 (file)
@@ -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, "");
index b33b0150ceb99cf28b344814824da7a88c477b46..6dfc835d78aa5255c3a239ad0512f4b3cddbd2c5 100644 (file)
@@ -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, "");