From patchwork Sun Mar 19 20:21:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 71865 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp861192wrt; Sun, 19 Mar 2023 13:21:58 -0700 (PDT) X-Google-Smtp-Source: AK7set8T86pzzoRcnOYBDVeyNeGtYVDzDBWdm9WcO38cJHVOehrEnibSbpfoa/4AqxrAw6/IIOgQ X-Received: by 2002:a05:6402:20d:b0:4fa:f133:54b7 with SMTP id t13-20020a056402020d00b004faf13354b7mr9835145edv.16.1679257318085; Sun, 19 Mar 2023 13:21:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1679257318; cv=none; d=google.com; s=arc-20160816; b=U/0wsngKVsHghSMR6aIfH6f9F0c36tYWJH6bf2gRNT4oTbYWUCe8POpAPlupqCugWr tKqeobvKiex67ccSM8K9dqfGrBtx/xQnGBL2M6MzplRDIeSvSDaTy6+thfI40nRUzIOy xj10y5bUw5KEG6iVlO06A8IHYc74SoxVRokZEAS3SBAs5KAOgm1P9BQi7w7eLUoYxUqY kMd/dhFfhna6ZuvcWyc1VpVoySrhBjrwwDnzeYzXV4YGmFFwNk3+6phn9pvFviC21rkm As3FxXMqaG3WDm36AcWr/E8bXLyqkpfGJbEISmrJ8p7SaAEjd3ZQuYY+I9IaQAZgrgC2 4RaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:cc:to:subject :message-id:date:mime-version:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=ciW4MvUWAzwmK5fFHAwrOIFfsrhM+MKzqJl0yTdiBw8=; b=xYZwfqwEmc7qlPuNRMVHMNP7jfFiNpuKxQ6j7hSIvX3nEyDFVhgRN0rY7DDkYfr83r ++ELmoW0aIJEZM/Gp48PabxW9nzv8xeXa04hEnRpycMLd9giuAKxY9aQm5RFecNvcxGz U5kEjsmlok3nTz9Ah2Y/hUYdnJJ8kZME6mIVVWvphL6qMVBti3PxfmfajVxNJWMKfyGi sdFJlEYV4RClIhT4F+elHfEtSoOPpyFKKAd8zULropv9aSAQDCgMvXfjw7S3o0hH+Mmn S4t8a+JSgMMYbJJvw8L5lLOU5pg1k7v3fV/OllppLlse0a/suW5GtsS1wKXafAviNoal d4ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="J/OHdJpM"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g23-20020aa7d1d7000000b004acce6da55bsi8443476edp.33.2023.03.19.13.21.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 19 Mar 2023 13:21:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b="J/OHdJpM"; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 134D03857BA4 for ; Sun, 19 Mar 2023 20:21:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 134D03857BA4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1679257317; bh=ciW4MvUWAzwmK5fFHAwrOIFfsrhM+MKzqJl0yTdiBw8=; h=Date:Subject:To:Cc:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=J/OHdJpM1wJSFkI3v1985UWhyC/mRReiE7wFG5MJhYlDfPv+cl7IEL474lK2wWeLE 6rKpWOl0aTUyu2UxpG1abBIaTe7TjzuDGXNVF4fOrQFGGJSMkeut1jLyXaUiuJSGSx 1kJkn4oKEQ7CG0t+L004U83vVHYTagSrOF0qT9aE= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ua1-x932.google.com (mail-ua1-x932.google.com [IPv6:2607:f8b0:4864:20::932]) by sourceware.org (Postfix) with ESMTPS id 6BD473858D37 for ; Sun, 19 Mar 2023 20:21:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6BD473858D37 Received: by mail-ua1-x932.google.com with SMTP id e12so1687865uaa.3 for ; Sun, 19 Mar 2023 13:21:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679257272; h=cc:to:subject:message-id:date:from:mime-version:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=ciW4MvUWAzwmK5fFHAwrOIFfsrhM+MKzqJl0yTdiBw8=; b=gUmFjA6TfgfSE7C+U4PkmrCX71K5XF9XUomCdCwkLq2OHtjn0XR9zaZhlFdc3qMLt6 NIoMIMjiiUxrT8bfvMqiH4c+RZkQZI2vqfKuXG4FijVLuyxGR1ODFTvx9LCqCcZV4lEz tbAqBBN3klpVSDGJOfG1G8NaJSHUWcpkMXH55GaLbrsV4UPg5VyB0ZT0q/wJwQrUAm6G 63WvqFkU0SZoeW0+iot/J5VHQsI+xi7InNFGHkcw8GJMFxXIbJpz8yZ2HZfsN3RiHhCl Rwj75krC/ionXA7NKEB5pUdX2E5hoOU2zCorM4yq60/OVdq9l5by+hnIhVKOybgzuYE9 6VkA== X-Gm-Message-State: AO0yUKXYS71IaFyO4ql1PX0ALi+gwKIltTtFnNGvD27ZijJWamokCpN9 rH+Updwt//vgDuDHFo5EEvhMpQep3aS9t+L6vcy1pzdXnUzFEPZIj0M= X-Received: by 2002:ab0:1006:0:b0:688:c23f:c22f with SMTP id f6-20020ab01006000000b00688c23fc22fmr2958301uab.1.1679257272605; Sun, 19 Mar 2023 13:21:12 -0700 (PDT) MIME-Version: 1.0 Date: Sun, 19 Mar 2023 13:21:01 -0700 Message-ID: Subject: [PATCH] c++: implement __remove_pointer built-in trait To: gcc-patches@gcc.gnu.org Cc: Patrick Palka X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Ken Matsui via Gcc-patches From: Ken Matsui Reply-To: Ken Matsui Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760828921791187211?= X-GMAIL-MSGID: =?utf-8?q?1760828921791187211?= 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. --- +SA(__is_same(__remove_pointer(int(*const volatile)(int)), int(int))); 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)));