public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Ken Matsui <kmatsui@cs.washington.edu>
To: gcc-patches@gcc.gnu.org
Cc: Patrick Palka <ppalka@redhat.com>
Subject: Re: [PATCH] c++: implement __remove_pointer built-in trait
Date: Mon, 20 Mar 2023 15:24:42 -0700	[thread overview]
Message-ID: <CAML+3pWaRbjzP56TgrfGZNOnGf5XSFkQ-HrHMEJJFFrTCByWbA@mail.gmail.com> (raw)
In-Reply-To: <CAML+3pWf_bYyeZcecrV=kmG_e6McD+JJPZuHJ2R2XeqJue6Wfw@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 5156 bytes --]

Please disregard this email.


On Sun, Mar 19, 2023 at 1:21 PM Ken Matsui <kmatsui@cs.washington.edu>
wrote:

> This patch implements built-in trait for std::remove_pointer.
>
> gcc/cp/ChangeLog:
>
> * cp-trait.def: Define __remove_pointer.
> * semantics.cc (finish_trait_type): Handle CPTK_REMOVE_POINTER.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/ext/has-builtin-1.C: Test existence of __remove_pointer.
> * g++.dg/ext/remove_pointer.C: New test.
>
> ---
> diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def
> index bac593c0094..985b43e0d97 100644
> --- a/gcc/cp/cp-trait.def
> +++ b/gcc/cp/cp-trait.def
> @@ -90,6 +90,7 @@ DEFTRAIT_EXPR (IS_DEDUCIBLE, "__is_deducible ", 2)
>  DEFTRAIT_TYPE (REMOVE_CV, "__remove_cv", 1)
>  DEFTRAIT_TYPE (REMOVE_REFERENCE, "__remove_reference", 1)
>  DEFTRAIT_TYPE (REMOVE_CVREF, "__remove_cvref", 1)
> +DEFTRAIT_TYPE (REMOVE_POINTER, "__remove_pointer", 1)
>  DEFTRAIT_TYPE (UNDERLYING_TYPE,  "__underlying_type", 1)
>
>  /* These traits yield a type pack, not a type, and are represented by
> diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
> index 87c2e8a7111..92db1f670ac 100644
> --- a/gcc/cp/semantics.cc
> +++ b/gcc/cp/semantics.cc
> @@ -12273,6 +12273,10 @@ 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_REMOVE_POINTER:
> +      if (TYPE_PTR_P (type1))
> +    type1 = TREE_TYPE (type1);
> +      return type1;
>
>  #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
>      case CPTK_##CODE:
> diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> b/gcc/testsuite/g++.dg/ext/has-builtin-1.C
> index f343e153e56..e21e0a95509 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 (__remove_pointer)
> +# error "__has_builtin (__remove_pointer) failed"
> +#endif
> diff --git a/gcc/testsuite/g++.dg/ext/remove_pointer.C
> b/gcc/testsuite/g++.dg/ext/remove_pointer.C
> new file mode 100644
> index 00000000000..7b13db93950
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/ext/remove_pointer.C
> @@ -0,0 +1,51 @@
> +// { dg-do compile { target c++11 } }
> +
> +#define SA(X) static_assert((X),#X)
> +
> +SA(__is_same(__remove_pointer(int), int));
> +SA(__is_same(__remove_pointer(int*), int));
> +SA(__is_same(__remove_pointer(int**), int*));
> +
> +SA(__is_same(__remove_pointer(const int*), const int));
> +SA(__is_same(__remove_pointer(const int**), const int*));
> +SA(__is_same(__remove_pointer(int* const), int));
> +SA(__is_same(__remove_pointer(int** const), int*));
> +SA(__is_same(__remove_pointer(int* const* const), int* const));
> +
> +SA(__is_same(__remove_pointer(volatile int*), volatile int));
> +SA(__is_same(__remove_pointer(volatile int**), volatile int*));
> +SA(__is_same(__remove_pointer(int* volatile), int));
> +SA(__is_same(__remove_pointer(int** volatile), int*));
> +SA(__is_same(__remove_pointer(int* volatile* volatile), int* volatile));
> +
> +SA(__is_same(__remove_pointer(const volatile int*), const volatile int));
> +SA(__is_same(__remove_pointer(const volatile int**), const volatile
> int*));
> +SA(__is_same(__remove_pointer(const int* volatile), const int));
> +SA(__is_same(__remove_pointer(volatile int* const), volatile int));
> +SA(__is_same(__remove_pointer(int* const volatile), int));
> +SA(__is_same(__remove_pointer(const int** volatile), const int*));
> +SA(__is_same(__remove_pointer(volatile int** const), volatile int*));
> +SA(__is_same(__remove_pointer(int** const volatile), int*));
> +SA(__is_same(__remove_pointer(int* const* const volatile), int* const));
> +SA(__is_same(__remove_pointer(int* volatile* const volatile), int*
> volatile));
> +SA(__is_same(__remove_pointer(int* const volatile* const volatile),
> int* const volatile));
> +
> +SA(__is_same(__remove_pointer(int&), int&));
> +SA(__is_same(__remove_pointer(const int&), const int&));
> +SA(__is_same(__remove_pointer(volatile int&), volatile int&));
> +SA(__is_same(__remove_pointer(const volatile int&), const volatile int&));
> +
> +SA(__is_same(__remove_pointer(int&&), int&&));
> +SA(__is_same(__remove_pointer(const int&&), const int&&));
> +SA(__is_same(__remove_pointer(volatile int&&), volatile int&&));
> +SA(__is_same(__remove_pointer(const volatile int&&), const volatile
> int&&));
> +
> +SA(__is_same(__remove_pointer(int[3]), int[3]));
> +SA(__is_same(__remove_pointer(const int[3]), const int[3]));
> +SA(__is_same(__remove_pointer(volatile int[3]), volatile int[3]));
> +SA(__is_same(__remove_pointer(const volatile int[3]), const volatile
> int[3]));
> +
> +SA(__is_same(__remove_pointer(int(int)), int(int)));
> +SA(__is_same(__remove_pointer(int(*const)(int)), int(int)));
> +SA(__is_same(__remove_pointer(int(*volatile)(int)), int(int)));
> +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int)));
>

      reply	other threads:[~2023-03-20 22:24 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-19 20:21 Ken Matsui
2023-03-20 22:24 ` Ken Matsui [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=CAML+3pWaRbjzP56TgrfGZNOnGf5XSFkQ-HrHMEJJFFrTCByWbA@mail.gmail.com \
    --to=kmatsui@cs.washington.edu \
    --cc=gcc-patches@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).