From: Jonathan Wakely <jwakely@redhat.com>
To: Ken Matsui <kmatsui@cs.washington.edu>
Cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org, ppalka@redhat.com
Subject: Re: [PATCH 1/2] c++: implement __add_const built-in trait
Date: Tue, 21 Mar 2023 11:29:23 +0000 [thread overview]
Message-ID: <CACb0b4=Gg0UO_LM_rWYKDQ4OkZtk9ZROs_LEwwK7FbJUWWrtfQ@mail.gmail.com> (raw)
In-Reply-To: <CACb0b4mKY=g5AQ8Z21sicXHegpuXCX0PR4eSyZ-g=WO=ZNczpw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 4911 bytes --]
On Tue, 21 Mar 2023 at 11:26, Jonathan Wakely wrote:
>
>
> On Tue, 21 Mar 2023 at 11:12, Ken Matsui via Libstdc++ <
> libstdc++@gcc.gnu.org> wrote:
>
>> This patch implements built-in trait for std::add_const.
>>
>> gcc/cp/ChangeLog:
>>
>> * cp-trait.def: Define __add_const.
>> * semantics.cc (finish_trait_type): Handle CPTK_ADD_CONST.
>>
>> gcc/testsuite/ChangeLog:
>>
>> * g++.dg/ext/has-builtin-1.C: Test existence of __add_const.
>> * g++.dg/ext/add_const.C: New test.
>> ---
>> gcc/cp/cp-trait.def | 1 +
>> gcc/cp/semantics.cc | 6 ++++
>> gcc/testsuite/g++.dg/ext/add_const.C | 39 ++++++++++++++++++++++++
>> gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++
>> 4 files changed, 49 insertions(+)
>> create mode 100644 gcc/testsuite/g++.dg/ext/add_const.C
>>
>> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
>> index bac593c0094..e362c448c84 100644
>> --- a/gcc/cp/cp-trait.def
>> +++ b/gcc/cp/cp-trait.def
>> @@ -91,6 +91,7 @@ DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1)
>> DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
>> DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1)
>> DEFTRAIT_TYPE (UNDERLYING_TYPE, "__underlying_type", 1)
>> +DEFTRAIT_TYPE (ADD_CONST, "__add_const", 1)
>>
>> /* These traits yield a type pack, not a type, and are represented by
>> cp_parser_trait as a special BASES tree instead of a TRAIT_TYPE
>> tree. */
>> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
>> index 87c2e8a7111..14e27a71a55 100644
>> --- a/gcc/cp/semantics.cc
>> +++ b/gcc/cp/semantics.cc
>> @@ -12273,6 +12273,12 @@ finish_trait_type (cp_trait_kind kind, tree
>> type1, tree type2)
>> if (TYPE_REF_P (type1))
>> type1 = TREE_TYPE (type1);
>> return cv_unqualified (type1);
>> + case CPTK_ADD_CONST:
>> + if (TYPE_REF_P (type1) || TYPE_PTRFN_P (type1))
>> + return type1;
>> + return cp_build_qualified_type (type1,
>> + cp_type_quals (type1) |
>> + TYPE_QUAL_CONST);
>>
>> #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
>> case CPTK_##CODE:
>> diff --git a/gcc/testsuite/g++.dg/ext/add_const.C
>> b/gcc/testsuite/g++.dg/ext/add_const.C
>> new file mode 100644
>> index 00000000000..1c8618a8b00
>> --- /dev/null
>> +++ b/gcc/testsuite/g++.dg/ext/add_const.C
>> @@ -0,0 +1,39 @@
>> +// { dg-do compile { target c++11 } }
>> +
>> +#define SA(X) static_assert((X),#X)
>> +
>> +SA(__is_same(__add_const(void), const void));
>> +SA(__is_same(__add_const(int), const int));
>> +
>> +SA(__is_same(__add_const(const int), const int));
>> +SA(__is_same(__add_const(volatile int), const volatile int));
>> +SA(__is_same(__add_const(const volatile int), const volatile int));
>> +
>> +SA(__is_same(__add_const(int*), int* const));
>> +SA(__is_same(__add_const(int* const), int* const));
>> +SA(__is_same(__add_const(int* volatile), int* const volatile));
>> +SA(__is_same(__add_const(int* const volatile), int* const volatile));
>> +
>> +SA(__is_same(__add_const(const int*), const int* const));
>> +SA(__is_same(__add_const(volatile int*), volatile int* const));
>> +SA(__is_same(__add_const(const volatile int*), const volatile int*
>> const));
>> +
>> +SA(__is_same(__add_const(int&), int&));
>> +SA(__is_same(__add_const(const int&), const int&));
>> +SA(__is_same(__add_const(volatile int&), volatile int&));
>> +SA(__is_same(__add_const(const volatile int&), const volatile int&));
>> +
>> +SA(__is_same(__add_const(int&&), int&&));
>> +SA(__is_same(__add_const(const int&&), const int&&));
>> +SA(__is_same(__add_const(volatile int&&), volatile int&&));
>> +SA(__is_same(__add_const(const volatile int&&), const volatile int&&));
>> +
>> +SA(__is_same(__add_const(int[3]), const int[3]));
>> +SA(__is_same(__add_const(const int[3]), const int[3]));
>> +SA(__is_same(__add_const(volatile int[3]), const volatile int[3]));
>> +SA(__is_same(__add_const(const volatile int[3]), const volatile int[3]));
>> +
>> +SA(__is_same(__add_const(int(int)), int(int)));
>> +SA(__is_same(__add_const(int(*const)(int)), int(*const)(int)));
>> +SA(__is_same(__add_const(int(*volatile)(int)), int(*volatile)(int)));
>>
>
> This looks wrong.
>
It might be useful to test pointer-to-member types too. And for
completeness, a class type.
>
>> +SA(__is_same(__add_const(int(*const volatile)(int)), int(*const
>> volatile)(int)));
>> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
>> b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
>> index f343e153e56..dd331ebbc9a 100644
>> --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
>> +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
>> @@ -146,3 +146,6 @@
>> #if !__has_builtin (__remove_cvref)
>> # error "__has_builtin (__remove_cvref) failed"
>> #endif
>> +#if !__has_builtin (__add_const)
>> +# error "__has_builtin (__add_const) failed"
>> +#endif
>> --
>> 2.40.0
>>
>>
prev parent reply other threads:[~2023-03-21 11:29 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-21 11:10 Ken Matsui
2023-03-21 11:10 ` [PATCH 2/2] libstdc++: use new built-in trait __add_const Ken Matsui
2023-03-21 11:20 ` Marc Glisse
2023-03-21 11:24 ` Jonathan Wakely
2023-03-21 11:37 ` Ken Matsui
2023-03-21 11:26 ` [PATCH 1/2] c++: implement __add_const built-in trait Jonathan Wakely
2023-03-21 11:29 ` Jonathan Wakely [this message]
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='CACb0b4=Gg0UO_LM_rWYKDQ4OkZtk9ZROs_LEwwK7FbJUWWrtfQ@mail.gmail.com' \
--to=jwakely@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=kmatsui@cs.washington.edu \
--cc=libstdc++@gcc.gnu.org \
--cc=ppalka@redhat.com \
/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).