aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2019-03-06 12:13:14 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2019-03-06 12:13:14 +0000
commit28d85efbfbcac8fc27e0ab4d4e27e5df8bdb402c (patch)
tree8ffbe0abfa0c8404f1cf9defd61e0211ffedd719
parentc24847a54abe6b93139f92318f254d1952315ba2 (diff)
downloadgcc-28d85efbfbcac8fc27e0ab4d4e27e5df8bdb402c.zip
gcc-28d85efbfbcac8fc27e0ab4d4e27e5df8bdb402c.tar.gz
gcc-28d85efbfbcac8fc27e0ab4d4e27e5df8bdb402c.tar.bz2
Add C++20 Traits for [Un]bounded Arrays (P1357R1)
* include/std/type_traits [C++20] (is_bounded_array) (is_unbounded_array, is_bounded_array_v, is_unbounded_array_v): Define. * testsuite/20_util/is_bounded_array/requirements/ explicit_instantiation.cc: New test. * testsuite/20_util/is_bounded_array/requirements/typedefs.cc: New test. * testsuite/20_util/is_bounded_array/value.cc: New test. * testsuite/20_util/is_unbounded_array/requirements/ explicit_instantiation.cc: New test. * testsuite/20_util/is_unbounded_array/requirements/typedefs.cc: New * test. * testsuite/20_util/is_unbounded_array/value.cc: New test. From-SVN: r269420
-rw-r--r--libstdc++-v3/ChangeLog14
-rw-r--r--libstdc++-v3/include/std/type_traits20
-rw-r--r--libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/explicit_instantiation.cc29
-rw-r--r--libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/typedefs.cc33
-rw-r--r--libstdc++-v3/testsuite/20_util/is_bounded_array/value.cc68
-rw-r--r--libstdc++-v3/testsuite/20_util/is_unbounded_array/requirements/explicit_instantiation.cc29
-rw-r--r--libstdc++-v3/testsuite/20_util/is_unbounded_array/requirements/typedefs.cc33
-rw-r--r--libstdc++-v3/testsuite/20_util/is_unbounded_array/value.cc67
8 files changed, 293 insertions, 0 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 053da2c..989ba25 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,19 @@
2019-03-06 Jonathan Wakely <jwakely@redhat.com>
+ * include/std/type_traits [C++20] (is_bounded_array)
+ (is_unbounded_array, is_bounded_array_v, is_unbounded_array_v):
+ Define.
+ * testsuite/20_util/is_bounded_array/requirements/
+ explicit_instantiation.cc: New test.
+ * testsuite/20_util/is_bounded_array/requirements/typedefs.cc: New
+ test.
+ * testsuite/20_util/is_bounded_array/value.cc: New test.
+ * testsuite/20_util/is_unbounded_array/requirements/
+ explicit_instantiation.cc: New test.
+ * testsuite/20_util/is_unbounded_array/requirements/typedefs.cc: New
+ * test.
+ * testsuite/20_util/is_unbounded_array/value.cc: New test.
+
* include/bits/ptr_traits.h [C++20] (pointer_traits<T*>::pointer_to):
Add constexpr.
* testsuite/20_util/pointer_traits/pointer_to_constexpr.cc: New test.
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 977ca0e..a1161d5 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3074,6 +3074,26 @@ template <typename _From, typename _To>
template<typename _Tp>
using unwrap_ref_decay_t = typename unwrap_ref_decay<_Tp>::type;
+ /// True for a type that is an array of known bound.
+ template<typename _Tp>
+ struct is_bounded_array
+ : public __is_array_known_bounds<_Tp>
+ { };
+
+ /// True for a type that is an array of unknown bound.
+ template<typename _Tp>
+ struct is_unbounded_array
+ : public __is_array_unknown_bounds<_Tp>
+ { };
+
+ template<typename _Tp>
+ inline constexpr bool is_bounded_array_v
+ = is_bounded_array<_Tp>::value;
+
+ template<typename _Tp>
+ inline constexpr bool is_unbounded_array_v
+ = is_unbounded_array<_Tp>::value;
+
#ifdef _GLIBCXX_HAVE_BUILTIN_IS_CONSTANT_EVALUATED
#define __cpp_lib_is_constant_evaluated 201811L
diff --git a/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/explicit_instantiation.cc
new file mode 100644
index 0000000..d7417a9
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/explicit_instantiation.cc
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+namespace std
+{
+ typedef short test_type;
+ template struct is_bounded_array<test_type>;
+}
diff --git a/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/typedefs.cc
new file mode 100644
index 0000000..abe430a
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_bounded_array/requirements/typedefs.cc
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// 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.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+void test01()
+{
+ // Check for required typedefs
+ typedef std::is_bounded_array<int> test_type;
+ typedef test_type::value_type value_type;
+ typedef test_type::type type;
+ typedef test_type::type::value_type type_value_type;
+ typedef test_type::type::type type_type;
+}
diff --git a/libstdc++-v3/testsuite/20_util/is_bounded_array/value.cc b/libstdc++-v3/testsuite/20_util/is_bounded_array/value.cc
new file mode 100644
index 0000000..9f37d36
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_bounded_array/value.cc
@@ -0,0 +1,68 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// 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.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <type_traits>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ using std::is_bounded_array;
+ using namespace __gnu_test;
+
+ static_assert(test_category<is_bounded_array, int[2]>(true), "");
+ static_assert(test_category<is_bounded_array, int[]>(false), "");
+ static_assert(test_category<is_bounded_array, int[2][3]>(true), "");
+ static_assert(test_category<is_bounded_array, int[][3]>(false), "");
+ static_assert(test_category<is_bounded_array, float*[2]>(true), "");
+ static_assert(test_category<is_bounded_array, float*[]>(false), "");
+ static_assert(test_category<is_bounded_array, float*[2][3]>(true), "");
+ static_assert(test_category<is_bounded_array, float*[][3]>(false), "");
+ static_assert(test_category<is_bounded_array, ClassType[2]>(true), "");
+ static_assert(test_category<is_bounded_array, ClassType[]>(false), "");
+ static_assert(test_category<is_bounded_array, ClassType[2][3]>(true), "");
+ static_assert(test_category<is_bounded_array, ClassType[][3]>(false), "");
+ static_assert(test_category<is_bounded_array, int(*)[2]>(false), "");
+ static_assert(test_category<is_bounded_array, int(*)[]>(false), "");
+ static_assert(test_category<is_bounded_array, int(&)[2]>(false), "");
+ static_assert(test_category<is_bounded_array, int(&)[]>(false), "");
+
+ // Sanity check.
+ static_assert(test_category<is_bounded_array, ClassType>(false), "");
+ static_assert(test_category<is_bounded_array, void()>(false), "");
+}
+
+template <class... T> void pos()
+{
+ static_assert((std::is_bounded_array_v<T> &&...));
+}
+
+template <class... T> void neg()
+{
+ static_assert((!std::is_bounded_array_v<T> &&...));
+}
+
+void test02()
+{
+ using namespace __gnu_test;
+ pos<int[2], int[2][3], float*[2], float*[2][3], ClassType[2],
+ ClassType[2][3]>();
+ neg<int[], int[][3], float*[], float*[][3], ClassType[],
+ ClassType[][3], int(*)[2], int(&)[], int(*)[2], int(&)[], ClassType>();
+}
diff --git a/libstdc++-v3/testsuite/20_util/is_unbounded_array/requirements/explicit_instantiation.cc b/libstdc++-v3/testsuite/20_util/is_unbounded_array/requirements/explicit_instantiation.cc
new file mode 100644
index 0000000..59cde80
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_unbounded_array/requirements/explicit_instantiation.cc
@@ -0,0 +1,29 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// 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.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+namespace std
+{
+ typedef short test_type;
+ template struct is_unbounded_array<test_type>;
+}
diff --git a/libstdc++-v3/testsuite/20_util/is_unbounded_array/requirements/typedefs.cc b/libstdc++-v3/testsuite/20_util/is_unbounded_array/requirements/typedefs.cc
new file mode 100644
index 0000000..abe430a
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_unbounded_array/requirements/typedefs.cc
@@ -0,0 +1,33 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// 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.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// NB: This file is for testing type_traits with NO OTHER INCLUDES.
+
+#include <type_traits>
+
+void test01()
+{
+ // Check for required typedefs
+ typedef std::is_bounded_array<int> test_type;
+ typedef test_type::value_type value_type;
+ typedef test_type::type type;
+ typedef test_type::type::value_type type_value_type;
+ typedef test_type::type::type type_type;
+}
diff --git a/libstdc++-v3/testsuite/20_util/is_unbounded_array/value.cc b/libstdc++-v3/testsuite/20_util/is_unbounded_array/value.cc
new file mode 100644
index 0000000..28a77b2
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/is_unbounded_array/value.cc
@@ -0,0 +1,67 @@
+// { dg-options "-std=gnu++2a" }
+// { dg-do compile { target c++2a } }
+
+// Copyright (C) 2019 Free Software Foundation, Inc.
+//
+// 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.
+//
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+#include <type_traits>
+#include <testsuite_tr1.h>
+
+void test01()
+{
+ using std::is_unbounded_array;
+ using namespace __gnu_test;
+
+ static_assert(test_category<is_unbounded_array, int[2]>(false), "");
+ static_assert(test_category<is_unbounded_array, int[]>(true), "");
+ static_assert(test_category<is_unbounded_array, int[2][3]>(false), "");
+ static_assert(test_category<is_unbounded_array, int[][3]>(true), "");
+ static_assert(test_category<is_unbounded_array, float*[2]>(false), "");
+ static_assert(test_category<is_unbounded_array, float*[]>(true), "");
+ static_assert(test_category<is_unbounded_array, float*[2][3]>(false), "");
+ static_assert(test_category<is_unbounded_array, float*[][3]>(true), "");
+ static_assert(test_category<is_unbounded_array, ClassType[2]>(false), "");
+ static_assert(test_category<is_unbounded_array, ClassType[]>(true), "");
+ static_assert(test_category<is_unbounded_array, ClassType[2][3]>(false), "");
+ static_assert(test_category<is_unbounded_array, ClassType[][3]>(true), "");
+ static_assert(test_category<is_unbounded_array, int(*)[2]>(false), "");
+ static_assert(test_category<is_unbounded_array, int(*)[]>(false), "");
+ static_assert(test_category<is_unbounded_array, int(&)[2]>(false), "");
+ static_assert(test_category<is_unbounded_array, int(&)[]>(false), "");
+
+ // Sanity check.
+ static_assert(test_category<is_unbounded_array, ClassType>(false), "");
+}
+
+template <class... T> void pos()
+{
+ static_assert((std::is_unbounded_array_v<T> &&...));
+}
+
+template <class... T> void neg()
+{
+ static_assert((!std::is_unbounded_array_v<T> &&...));
+}
+
+void test02()
+{
+ using namespace __gnu_test;
+ pos<int[], int[][3], float*[], float*[][3], ClassType[],
+ ClassType[][3]>();
+ neg<int[2], int[2][3], float*[2], float*[2][3], ClassType[2],
+ ClassType[2][3], int(*)[2], int(&)[], int(*)[2], int(&)[], ClassType>();
+}