aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Matsui <kmatsui@gcc.gnu.org>2024-02-14 05:49:35 -0800
committerKen Matsui <kmatsui@gcc.gnu.org>2024-05-10 18:16:49 -0700
commite1ca1fa1c7a347088551aa7de521d2a87c1a7863 (patch)
tree45d20b269a183f258a16a779dc7e7c4d0d51fb21
parent2763f81e0b93700bc879690ce2a7d258c3989924 (diff)
downloadgcc-e1ca1fa1c7a347088551aa7de521d2a87c1a7863.zip
gcc-e1ca1fa1c7a347088551aa7de521d2a87c1a7863.tar.gz
gcc-e1ca1fa1c7a347088551aa7de521d2a87c1a7863.tar.bz2
c++: Implement __remove_extent built-in trait
This patch implements built-in trait for std::remove_extent. gcc/cp/ChangeLog: * cp-trait.def: Define __remove_extent. * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_EXTENT. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __remove_extent. * g++.dg/ext/remove_extent.C: New test. Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org> Reviewed-by: Jason Merrill <jason@redhat.com>
-rw-r--r--gcc/cp/cp-trait.def1
-rw-r--r--gcc/cp/semantics.cc5
-rw-r--r--gcc/testsuite/g++.dg/ext/has-builtin-1.C3
-rw-r--r--gcc/testsuite/g++.dg/ext/remove_extent.C16
4 files changed, 25 insertions, 0 deletions
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 63f8792..577c96d 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -100,6 +100,7 @@ DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_tempo
DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2)
DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1)
DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1)
+DEFTRAIT_TYPE (REMOVE_EXTENT, "__remove_extent", 1)
DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1)
DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
DEFTRAIT_TYPE (TYPE_PACK_ELEMENT, "__type_pack_element", -1)
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 4920b56..b2122ce 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12942,6 +12942,11 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
type1 = TREE_TYPE (type1);
return cv_unqualified (type1);
+ case CPTK_REMOVE_EXTENT:
+ if (TREE_CODE (type1) == ARRAY_TYPE)
+ type1 = TREE_TYPE (type1);
+ return type1;
+
case CPTK_REMOVE_POINTER:
if (TYPE_PTR_P (type1))
type1 = TREE_TYPE (type1);
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index bd9e064..d58e418 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -182,6 +182,9 @@
#if !__has_builtin (__remove_cvref)
# error "__has_builtin (__remove_cvref) failed"
#endif
+#if !__has_builtin (__remove_extent)
+# error "__has_builtin (__remove_extent) failed"
+#endif
#if !__has_builtin (__remove_pointer)
# error "__has_builtin (__remove_pointer) failed"
#endif
diff --git a/gcc/testsuite/g++.dg/ext/remove_extent.C b/gcc/testsuite/g++.dg/ext/remove_extent.C
new file mode 100644
index 0000000..6183aca
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/remove_extent.C
@@ -0,0 +1,16 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+class ClassType { };
+
+SA(__is_same(__remove_extent(int), int));
+SA(__is_same(__remove_extent(int[2]), int));
+SA(__is_same(__remove_extent(int[2][3]), int[3]));
+SA(__is_same(__remove_extent(int[][3]), int[3]));
+SA(__is_same(__remove_extent(const int[2]), const int));
+SA(__is_same(__remove_extent(ClassType), ClassType));
+SA(__is_same(__remove_extent(ClassType[2]), ClassType));
+SA(__is_same(__remove_extent(ClassType[2][3]), ClassType[3]));
+SA(__is_same(__remove_extent(ClassType[][3]), ClassType[3]));
+SA(__is_same(__remove_extent(const ClassType[2]), const ClassType));