From: Ken Matsui <kmatsui@gcc.gnu.org>
To: gcc-patches@gcc.gnu.org
Cc: libstdc++@gcc.gnu.org, Ken Matsui <kmatsui@gcc.gnu.org>
Subject: [PATCH v5 09/14] c++: Implement __add_rvalue_reference built-in trait
Date: Thu, 15 Feb 2024 07:20:32 -0800 [thread overview]
Message-ID: <20240215152037.720162-9-kmatsui@gcc.gnu.org> (raw)
In-Reply-To: <20240215152037.720162-1-kmatsui@gcc.gnu.org>
This patch implements built-in trait for std::add_rvalue_reference.
gcc/cp/ChangeLog:
* cp-trait.def: Define __add_rvalue_reference.
* semantics.cc (finish_trait_type): Handle
CPTK_ADD_RVALUE_REFERENCE.
gcc/testsuite/ChangeLog:
* g++.dg/ext/has-builtin-1.C: Test existence of
__add_rvalue_reference.
* g++.dg/ext/add_rvalue_reference.C: New test.
Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
gcc/cp/cp-trait.def | 1 +
gcc/cp/semantics.cc | 8 ++++++++
.../g++.dg/ext/add_rvalue_reference.C | 20 +++++++++++++++++++
gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 +++
4 files changed, 32 insertions(+)
create mode 100644 gcc/testsuite/g++.dg/ext/add_rvalue_reference.C
diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
index 7dcc6bbad76..9e8f9eb38b8 100644
--- a/gcc/cp/cp-trait.def
+++ b/gcc/cp/cp-trait.def
@@ -50,6 +50,7 @@
DEFTRAIT_TYPE (ADD_LVALUE_REFERENCE, "__add_lvalue_reference", 1)
DEFTRAIT_TYPE (ADD_POINTER, "__add_pointer", 1)
+DEFTRAIT_TYPE (ADD_RVALUE_REFERENCE, "__add_rvalue_reference", 1)
DEFTRAIT_EXPR (HAS_NOTHROW_ASSIGN, "__has_nothrow_assign", 1)
DEFTRAIT_EXPR (HAS_NOTHROW_CONSTRUCTOR, "__has_nothrow_constructor", 1)
DEFTRAIT_EXPR (HAS_NOTHROW_COPY, "__has_nothrow_copy", 1)
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index 82fc31d9f9b..f437e272ea6 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -12777,6 +12777,14 @@ finish_trait_type (cp_trait_kind kind, tree type1, tree type2,
type1 = TREE_TYPE (type1);
return build_pointer_type (type1);
+ case CPTK_ADD_RVALUE_REFERENCE:
+ if (VOID_TYPE_P (type1)
+ || (FUNC_OR_METHOD_TYPE_P (type1)
+ && (type_memfn_quals (type1) != TYPE_UNQUALIFIED
+ || type_memfn_rqual (type1) != REF_QUAL_NONE)))
+ return type1;
+ return cp_build_reference_type (type1, /*rval=*/true);
+
case CPTK_REMOVE_ALL_EXTENTS:
return strip_array_types (type1);
diff --git a/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C
new file mode 100644
index 00000000000..c92fe6bfa17
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/add_rvalue_reference.C
@@ -0,0 +1,20 @@
+// { dg-do compile { target c++11 } }
+
+#define SA(X) static_assert((X),#X)
+
+class ClassType { };
+
+SA(__is_same(__add_rvalue_reference(int), int&&));
+SA(__is_same(__add_rvalue_reference(int&&), int&&));
+SA(__is_same(__add_rvalue_reference(int&), int&));
+SA(__is_same(__add_rvalue_reference(const int), const int&&));
+SA(__is_same(__add_rvalue_reference(int*), int*&&));
+SA(__is_same(__add_rvalue_reference(ClassType&&), ClassType&&));
+SA(__is_same(__add_rvalue_reference(ClassType), ClassType&&));
+SA(__is_same(__add_rvalue_reference(int(int)), int(&&)(int)));
+SA(__is_same(__add_rvalue_reference(void), void));
+SA(__is_same(__add_rvalue_reference(const void), const void));
+SA(__is_same(__add_rvalue_reference(bool(int) const), bool(int) const));
+SA(__is_same(__add_rvalue_reference(bool(int) &), bool(int) &));
+SA(__is_same(__add_rvalue_reference(bool(int) const &&), bool(int) const &&));
+SA(__is_same(__add_rvalue_reference(bool(int)), bool(&&)(int)));
diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
index 1046ffe7d01..9d7e59b47fb 100644
--- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
+++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
@@ -8,6 +8,9 @@
#if !__has_builtin (__add_pointer)
# error "__has_builtin (__add_pointer) failed"
#endif
+#if !__has_builtin (__add_rvalue_reference)
+# error "__has_builtin (__add_rvalue_reference) failed"
+#endif
#if !__has_builtin (__builtin_addressof)
# error "__has_builtin (__builtin_addressof) failed"
#endif
--
2.43.0
next prev parent reply other threads:[~2024-02-15 15:21 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-14 11:44 [PATCH 1/2] c++: Implement __add_pointer " Ken Matsui
2024-02-14 11:44 ` [PATCH 2/2] libstdc++: Optimize std::add_pointer compilation performance Ken Matsui
2024-02-14 13:52 ` [PATCH v2 1/4] c++: Implement __add_pointer built-in trait Ken Matsui
2024-02-14 13:52 ` [PATCH v2 2/4] libstdc++: Optimize std::add_pointer compilation performance Ken Matsui
2024-02-14 20:20 ` Patrick Palka
2024-02-14 13:52 ` [PATCH v2 3/4] c++: Implement __remove_extent built-in trait Ken Matsui
2024-02-14 20:20 ` Patrick Palka
2024-02-14 13:52 ` [PATCH v2 4/4] libstdc++: Optimize std::remove_extent compilation performance Ken Matsui
2024-02-14 20:21 ` Patrick Palka
2024-02-14 20:18 ` [PATCH v2 1/4] c++: Implement __add_pointer built-in trait Patrick Palka
2024-02-15 4:17 ` Ken Matsui
2024-02-15 4:52 ` [PATCH v3 " Ken Matsui
2024-02-15 12:48 ` [PATCH v4 05/12] c++: Implement __remove_all_extents " Ken Matsui
2024-02-15 12:48 ` [PATCH v4 06/12] libstdc++: Optimize std::remove_all_extents compilation performance Ken Matsui
2024-02-15 12:48 ` [PATCH v4 07/12] c++: Implement __add_lvalue_reference built-in trait Ken Matsui
2024-02-15 12:48 ` [PATCH v4 08/12] libstdc++: Optimize std::add_lvalue_reference compilation performance Ken Matsui
2024-02-15 12:48 ` [PATCH v4 09/12] c++: Implement __add_rvalue_reference built-in trait Ken Matsui
2024-02-15 12:48 ` [PATCH v4 10/12] libstdc++: Optimize std::add_rvalue_reference compilation performance Ken Matsui
2024-02-15 12:48 ` [PATCH v4 11/12] c++: Implement __decay built-in trait Ken Matsui
2024-02-15 12:48 ` [PATCH v4 12/12] libstdc++: Optimize std::decay compilation performance Ken Matsui
2024-02-15 15:20 ` [PATCH v5 01/14] c++: Implement __add_pointer built-in trait Ken Matsui
2024-02-15 15:20 ` [PATCH v5 02/14] libstdc++: Optimize std::add_pointer compilation performance Ken Matsui
2024-02-15 15:20 ` [PATCH v5 03/14] c++: Implement __remove_extent built-in trait Ken Matsui
2024-02-15 15:20 ` [PATCH v5 04/14] libstdc++: Optimize std::remove_extent compilation performance Ken Matsui
2024-02-15 15:20 ` [PATCH v5 05/14] c++: Implement __remove_all_extents built-in trait Ken Matsui
2024-02-15 15:20 ` [PATCH v5 06/14] libstdc++: Optimize std::remove_all_extents compilation performance Ken Matsui
2024-02-15 15:20 ` [PATCH v5 07/14] c++: Implement __add_lvalue_reference built-in trait Ken Matsui
2024-02-15 15:20 ` [PATCH v5 08/14] libstdc++: Optimize std::add_lvalue_reference compilation performance Ken Matsui
2024-02-15 15:20 ` Ken Matsui [this message]
2024-02-15 15:20 ` [PATCH v5 10/14] libstdc++: Optimize std::add_rvalue_reference " Ken Matsui
2024-02-15 15:20 ` [PATCH v5 11/14] c++: Implement __decay built-in trait Ken Matsui
2024-02-15 15:20 ` [PATCH v5 12/14] libstdc++: Optimize std::decay compilation performance Ken Matsui
2024-02-15 15:20 ` [PATCH v5 13/14] c++: Implement __rank built-in trait Ken Matsui
2024-02-15 21:48 ` Patrick Palka
2024-02-16 2:14 ` Ken Matsui
2024-02-16 2:22 ` Ken Matsui
2024-02-16 2:15 ` [PATCH v6 " Ken Matsui
2024-02-15 15:20 ` [PATCH v5 14/14] libstdc++: Optimize std::rank compilation performance Ken Matsui
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240215152037.720162-9-kmatsui@gcc.gnu.org \
--to=kmatsui@gcc.gnu.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=libstdc++@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).