From patchwork Thu Jul 13 03:16:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1561074vqm; Wed, 12 Jul 2023 20:18:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlHhHJnFYGJszdHQFBIph3SgrTIzZT9mSgnZ30ljGOpItx3JzSXKx3WxwbxbuaIUKIhRfYlx X-Received: by 2002:aa7:d359:0:b0:51e:4bd6:ce4a with SMTP id m25-20020aa7d359000000b0051e4bd6ce4amr658278edr.11.1689218297597; Wed, 12 Jul 2023 20:18:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689218297; cv=none; d=google.com; s=arc-20160816; b=K0hsHjaYVfi6Zo7CVE06iBu0hfD8UUEDXclbFAhme7oJhoTgC1ukFs4iJs96dZwRcU BgxQ+/3VzoqXm5jxWqZvL8mB18K+KTdGzjwJpiwIO9wdz9TrHq98Rj0GwBHmzTDvycnS bUV1M7NJcU6eXyfdwjtMReSlB8t2fY8oZEvZ9480+1cGJfVRFaThgabXHFl6BojyeYZE xkZSUhfoxgAyEA9TM4Wuf7YUbvCjfIO3WdOcTVdIlZb+cRZuLNBkaWg2zVRMO5Y7JYRQ EXKxNZ6UcFaMTBF508J+mh3AA1DA+cvNJe6qAc36AWQ2Mw/yS1cxOSsyg9k+DNtAZl8R jJyg== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=0Xqtpp/4GNkUosnHca9FfieNUsZIPsxpvDBDnElW3Oc=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=JXkJw4hEk3hW74/A92A3zbNUyyoFckbbR/tNclewjHMr8gwc7u4T3/3Q+Lq4dEwMJH ruu4Rhk0iMe0vcQMSNhwvakJXFFgC3UkKzocFHDr5btmAHLuCUgZ6hc8lvOXS8eK0QX5 BAE77AMJzAQASgfnA0uUjmTbxEZ/fk8ammcjT93VehdzX4CCFtLE5kdqKOY9zBVYxxwT Z3ldcNCyjeWKrEP6Ktw6FK5tG4OwJHGWbk5hkixawyaQoi8uk1PRsYYPotoiiOobTsUH VnZSuv+fheQstpBJCuK+ZArVmIb2+NaI4JGxSguaTP1PqxPS9FzJDgS8pCqEC23uf8Zz pSsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=x3a0Jjs3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id p7-20020a056402074700b0051dd1c4b760si6408917edy.630.2023.07.12.20.18.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 20:18:17 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=x3a0Jjs3; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 1F12F3854EAB for ; Thu, 13 Jul 2023 03:17:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1F12F3854EAB DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689218249; bh=0Xqtpp/4GNkUosnHca9FfieNUsZIPsxpvDBDnElW3Oc=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=x3a0Jjs3DTYosoNJm1JMDCFRyhRliJPmIK790uqBIGmG2X6qZfBoJ5NtoEBC6Izd9 qKOREaKcmo9/OAmPMtrfG/yHD8kEkTY+jkrQQdFG+KwtAPv1dmiRmC7u9+EmrgmnXX yFwKeF5t9uQAvLkJenVRZVxPM8LqOnSjQv2KVSi4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0a-00641c01.pphosted.com (mx0a-00641c01.pphosted.com [205.220.165.146]) by sourceware.org (Postfix) with ESMTPS id D59853858C74; Thu, 13 Jul 2023 03:16:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D59853858C74 Received: from pps.filterd (m0247475.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36D3DBj2012653; Thu, 13 Jul 2023 03:16:33 GMT Received: from mxout22.s.uw.edu (mxout22.s.uw.edu [128.95.242.222]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rsy34vn8v-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 03:16:33 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout22.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36D3G5jD003029 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 20:16:05 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.234]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 36D3G54Q000857 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 20:16:05 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v4 1/2] c++, libstdc++: Implement __is_pointer built-in trait Date: Wed, 12 Jul 2023 20:16:00 -0700 Message-ID: <20230713031601.17787-1-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713011127.98367-1-kmatsui@gcc.gnu.org> References: <20230713011127.98367-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: or5aSeGE7pzdknRENOOey45rZ2SQrTCp X-Proofpoint-ORIG-GUID: or5aSeGE7pzdknRENOOey45rZ2SQrTCp X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-12_17,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 priorityscore=1501 adultscore=0 mlxlogscore=999 lowpriorityscore=0 bulkscore=0 spamscore=0 impostorscore=0 clxscore=1034 mlxscore=0 suspectscore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307130027 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1771265895314173755 X-GMAIL-MSGID: 1771273765594136900 This patch implements built-in trait for std::is_pointer. gcc/cp/ChangeLog: * cp-trait.def: Define __is_pointer. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_POINTER. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_pointer. * g++.dg/ext/is_pointer.C: New test. * g++.dg/tm/pr46567.C (__is_pointer): Rename to ... (__is_ptr): ... this. * g++.dg/torture/20070621-1.C: Likewise. * g++.dg/torture/pr57107.C: Likewise. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_pointer): Rename to ... (__is_ptr): ... this. * include/bits/deque.tcc: Use __is_ptr instead. * include/bits/stl_algobase.h: Likewise. Signed-off-by: Ken Matsui --- gcc/cp/constraint.cc | 3 ++ gcc/cp/cp-trait.def | 1 + gcc/cp/semantics.cc | 4 ++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 3 ++ gcc/testsuite/g++.dg/ext/is_pointer.C | 51 +++++++++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 22 ++++----- gcc/testsuite/g++.dg/torture/20070621-1.C | 4 +- gcc/testsuite/g++.dg/torture/pr57107.C | 4 +- libstdc++-v3/include/bits/cpp_type_traits.h | 6 +-- libstdc++-v3/include/bits/deque.tcc | 6 +-- libstdc++-v3/include/bits/stl_algobase.h | 6 +-- 11 files changed, 86 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_pointer.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 8cf0f2d0974..30266204eb5 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3751,6 +3751,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_POINTER: + inform (loc, " %qT is not a pointer", t1); + break; case CPTK_IS_AGGREGATE: inform (loc, " %qT is not an aggregate", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 8b7fece0cc8..b7c263e9a77 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -82,6 +82,7 @@ DEFTRAIT_EXPR (IS_TRIVIALLY_ASSIGNABLE, "__is_trivially_assignable", 2) DEFTRAIT_EXPR (IS_TRIVIALLY_CONSTRUCTIBLE, "__is_trivially_constructible", -1) DEFTRAIT_EXPR (IS_TRIVIALLY_COPYABLE, "__is_trivially_copyable", 1) DEFTRAIT_EXPR (IS_UNION, "__is_union", 1) +DEFTRAIT_EXPR (IS_POINTER, "__is_pointer", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) /* FIXME Added space to avoid direct usage in GCC 13. */ diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 8fb47fd179e..68f8a4fe85b 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12118,6 +12118,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_POINTER: + return TYPE_PTR_P (type1); + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12296,6 +12299,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: case CPTK_IS_UNION: case CPTK_IS_SAME: + case CPTK_IS_POINTER: break; case CPTK_IS_LAYOUT_COMPATIBLE: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..9dace5cbd48 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 (__is_pointer) +# error "__has_builtin (__is_pointer) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_pointer.C b/gcc/testsuite/g++.dg/ext/is_pointer.C new file mode 100644 index 00000000000..d6e39565950 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_pointer.C @@ -0,0 +1,51 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +SA(!__is_pointer(int)); +SA(__is_pointer(int*)); +SA(__is_pointer(int**)); + +SA(__is_pointer(const int*)); +SA(__is_pointer(const int**)); +SA(__is_pointer(int* const)); +SA(__is_pointer(int** const)); +SA(__is_pointer(int* const* const)); + +SA(__is_pointer(volatile int*)); +SA(__is_pointer(volatile int**)); +SA(__is_pointer(int* volatile)); +SA(__is_pointer(int** volatile)); +SA(__is_pointer(int* volatile* volatile)); + +SA(__is_pointer(const volatile int*)); +SA(__is_pointer(const volatile int**)); +SA(__is_pointer(const int* volatile)); +SA(__is_pointer(volatile int* const)); +SA(__is_pointer(int* const volatile)); +SA(__is_pointer(const int** volatile)); +SA(__is_pointer(volatile int** const)); +SA(__is_pointer(int** const volatile)); +SA(__is_pointer(int* const* const volatile)); +SA(__is_pointer(int* volatile* const volatile)); +SA(__is_pointer(int* const volatile* const volatile)); + +SA(!__is_pointer(int&)); +SA(!__is_pointer(const int&)); +SA(!__is_pointer(volatile int&)); +SA(!__is_pointer(const volatile int&)); + +SA(!__is_pointer(int&&)); +SA(!__is_pointer(const int&&)); +SA(!__is_pointer(volatile int&&)); +SA(!__is_pointer(const volatile int&&)); + +SA(!__is_pointer(int[3])); +SA(!__is_pointer(const int[3])); +SA(!__is_pointer(volatile int[3])); +SA(!__is_pointer(const volatile int[3])); + +SA(!__is_pointer(int(int))); +SA(__is_pointer(int(*const)(int))); +SA(__is_pointer(int(*volatile)(int))); +SA(__is_pointer(int(*const volatile)(int))); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 6d791484448..f08bbf6fd7b 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -192,13 +192,13 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef __true_type __type; }; template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -226,7 +226,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { { }; template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; template struct __is_char @@ -1202,8 +1202,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_OI>::value_type _ValueTypeO; typedef typename iterator_traits<_II>::iterator_category _Category; const bool __simple = (__is_pod(_ValueTypeI) - && __is_pointer<_II>::__value - && __is_pointer<_OI>::__value + && __is_ptr<_II>::__value + && __is_ptr<_OI>::__value && __are_same<_ValueTypeI, _ValueTypeO>::__value); return std::__copy_move<_IsMove, __simple, _Category>::__copy_m(__first, __last, __result); @@ -1294,8 +1294,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_BI2>::value_type _ValueType2; typedef typename iterator_traits<_BI1>::iterator_category _Category; const bool __simple = (__is_pod(_ValueType1) - && __is_pointer<_BI1>::__value - && __is_pointer<_BI2>::__value + && __is_ptr<_BI1>::__value + && __is_ptr<_BI2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__copy_move_backward<_IsMove, __simple, _Category>::__copy_move_b(__first, @@ -1426,8 +1426,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_integer<_ValueType1>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1515,8 +1515,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value); + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, __first2, __last2); } diff --git a/gcc/testsuite/g++.dg/torture/20070621-1.C b/gcc/testsuite/g++.dg/torture/20070621-1.C index d8a6a76b6b0..b05136163e8 100644 --- a/gcc/testsuite/g++.dg/torture/20070621-1.C +++ b/gcc/testsuite/g++.dg/torture/20070621-1.C @@ -18,7 +18,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -49,7 +49,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { template inline bool __equal_aux(_II1 __first1, _II1 __last1, _II2 __first2) { typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; - const bool __simple = (__is_integer<_ValueType1>::__value && __is_pointer<_II1>::__value && __is_pointer<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); + const bool __simple = (__is_integer<_ValueType1>::__value && __is_ptr<_II1>::__value && __is_ptr<_II2>::__value && __are_same<_ValueType1, _ValueType2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } template inline bool equal(_II1 __first1, _II1 __last1, _II2 __first2) { diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index 4dbd32bd298..be0689096fb 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -17,7 +17,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { enum { __value = 0 }; }; - template struct __is_pointer { + template struct __is_ptr { enum { __value = 0 }; }; @@ -27,7 +27,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template struct __is_arithmetic : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > { + template struct __is_scalar : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..3711e4be526 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -364,14 +364,14 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // Pointer types // template - struct __is_pointer + struct __is_ptr { enum { __value = 0 }; typedef __false_type __type; }; template - struct __is_pointer<_Tp*> + struct __is_ptr<_Tp*> { enum { __value = 1 }; typedef __true_type __type; @@ -390,7 +390,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // template struct __is_scalar - : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > + : public __traitor<__is_arithmetic<_Tp>, __is_ptr<_Tp> > { }; // diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index a212b8a6940..08d888ee8af 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -1273,7 +1273,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr>::__value + && __is_ptr<_Ptr>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with @@ -1329,8 +1329,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { const bool __simple = (__is_memcmp_ordered_with<_Tp1, _Tp2>::__value - && __is_pointer<_Ptr1>::__value - && __is_pointer<_Ptr2>::__value + && __is_ptr<_Ptr1>::__value + && __is_ptr<_Ptr2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index dd95e94f7e9..cf21611fa5c 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -1214,7 +1214,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER { typedef typename iterator_traits<_II1>::value_type _ValueType1; const bool __simple = ((__is_integer<_ValueType1>::__value - || __is_pointer<_ValueType1>::__value) + || __is_ptr<_ValueType1>::__value) && __memcmpable<_II1, _II2>::__value); return std::__equal<__simple>::equal(__first1, __last1, __first2); } @@ -1377,8 +1377,8 @@ _GLIBCXX_END_NAMESPACE_CONTAINER typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_memcmp_ordered_with<_ValueType1, _ValueType2>::__value - && __is_pointer<_II1>::__value - && __is_pointer<_II2>::__value + && __is_ptr<_II1>::__value + && __is_ptr<_II2>::__value #if __cplusplus > 201703L && __cpp_lib_concepts // For C++20 iterator_traits::value_type is non-volatile // so __is_byte could be true, but we can't use memcmp with From patchwork Thu Jul 13 03:16: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: 119492 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1561519vqm; Wed, 12 Jul 2023 20:19:47 -0700 (PDT) X-Google-Smtp-Source: APBJJlFmjOGQRLa2kTSTE/KHK+BiNoDIObc7MK0odN1+wZpD1TQrB8QoW3UjM4UrUfANjT9ji+ii X-Received: by 2002:a17:907:310d:b0:973:d076:67ab with SMTP id wl13-20020a170907310d00b00973d07667abmr164103ejb.42.1689218387619; Wed, 12 Jul 2023 20:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689218387; cv=none; d=google.com; s=arc-20160816; b=bbOpcc946FRIzn8fCkX6TC6GZaASfq+fYUatSYcxP2PLiZAO1b5BAFZwIFc1CZHrN5 aXe5gW25K7S2vR9kE8TfUqoVihMluLfJblI1uDs6fsE4gLSIKLNLgOfTDe4mRnHOSHPH nnA7EwRvLteNFu/Qto8503miss2hdmK4OOZRGVYl+fjyhryVzhHmRged6L4RD1chjH4m WNEduecFzGrQOW8pSriYVSs0jqP6wLHtrzFHyZurYVuLFqbOiqcvd7/nuC7rHNHQOzfY JBoxy+hhGIKIQXy/QimGBPUtaFqV7rkOPNIxsYJkMy3Bq8R+UW5APIGqxHXp+fUtQVvA rA1A== 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 :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=fz5/9SXF1snOY8f7fSgtHTMTWmOnPA6taeZ43WBhnTE=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=QL7G0lP7iTxN1L647penMFOsCLj4geFIu9/9xEjcX2+i0ia2TCMygcBbunm8lduVDU MHnvz/ZAPq3wSrDE3mzq1LCU7Rmigjk8aS2SiD0wBszRrs1kuH1jyHp0L4EtPp8cKOBm Ppb4Rf3L8sbb4my4p8cTPwf74kdVXTtk/Hyf7bVp+isRkbz315am2hvgFYBCOFl9110q pFRAKbo2ncXu9yE8NREwjCI38+IbTBO24WYEhSziwZzvptNi6GNNhwcG5DmRez9puPnt SkH3LR4OSRwd4UQKSZOCo4S+bOsSHH+995sPKLhzy8CPhFzae340CVf1S1b6RIQGnG4U y6nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dbgrn3N2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id la9-20020a170906ad8900b009935121ecd5si6137488ejb.646.2023.07.12.20.19.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 20:19:47 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=dbgrn3N2; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 2F1633854EBE for ; Thu, 13 Jul 2023 03:18:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2F1633854EBE DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689218306; bh=fz5/9SXF1snOY8f7fSgtHTMTWmOnPA6taeZ43WBhnTE=; h=To:Cc:Subject:Date:In-Reply-To:References:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From:Reply-To:From; b=dbgrn3N28PmCz3l7Z/cLGD2Z5zXvcFP9k19U+z49k0xAmXvkHCQ/gl8a7JISWV/4K JlwQVzErSPjOnanGZ0TnGbTrhPvBOUW/z8LpH/Yc8Z7qjyWTbjtPac6ABYLcbxwCHs Y5DPYo2YMGSeGf5RT6A6ddL/qUbUh4Vdp6PlrJdk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mx0b-00641c01.pphosted.com (mx0b-00641c01.pphosted.com [205.220.177.146]) by sourceware.org (Postfix) with ESMTPS id 3387A38555B9; Thu, 13 Jul 2023 03:17:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3387A38555B9 Received: from pps.filterd (m0247480.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36D3GUrt012532; Thu, 13 Jul 2023 03:17:16 GMT Received: from mxout23.cac.washington.edu (mxout23.cac.washington.edu [140.142.32.140]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rsgbah14t-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 03:17:16 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.132]) by mxout23.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36D3H14o011937 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 20:17:01 -0700 X-Auth-Received: from localhost.localdomain ([10.154.74.234]) (authenticated authid=kmatsui) by smtp.washington.edu (8.16.1+UW21.10/8.14.4+UW19.10) with ESMTPSA id 36D3G54R000857 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 20:17:01 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v4 2/2] libstdc++: Use new built-in trait __is_pointer Date: Wed, 12 Jul 2023 20:16:01 -0700 Message-ID: <20230713031601.17787-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713031601.17787-1-kmatsui@gcc.gnu.org> References: <20230713011127.98367-1-kmatsui@gcc.gnu.org> <20230713031601.17787-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: Pr873vigJ3KsBbaky8mKFhQubRwQ0W5W X-Proofpoint-GUID: Pr873vigJ3KsBbaky8mKFhQubRwQ0W5W X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-12_17,2023-07-11_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 bulkscore=0 impostorscore=0 priorityscore=1501 clxscore=1034 mlxlogscore=568 phishscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307130027 X-Spam-Status: No, score=-13.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NEUTRAL, TXREP, T_SCC_BODY_TEXT_LINE 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: INBOX X-GMAIL-THRID: 1771266095205163215 X-GMAIL-MSGID: 1771273859930021007 This patch lets libstdc++ use new built-in trait __is_pointer. libstdc++-v3/ChangeLog: * include/bits/cpp_type_traits.h (__is_ptr): Use __is_pointer built-in trait. * include/std/type_traits (is_pointer): Likewise. Optimize its implementation. (is_pointer_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++ libstdc++-v3/include/std/type_traits | 45 +++++++++++++++++---- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 3711e4be526..4da1e7c407c 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -363,6 +363,13 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) // // Pointer types // +#if __has_builtin(__is_pointer) + template + struct __is_ptr : __truth_type<__is_pointer(_Tp)> + { + enum { __value = __is_pointer(_Tp) }; + }; +#else template struct __is_ptr { @@ -376,6 +383,7 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) enum { __value = 1 }; typedef __true_type __type; }; +#endif // // An arithmetic type is an integer type or a floating point type diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 0e7a9c9c7f3..0743db4cb51 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -515,19 +515,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_array<_Tp[]> : public true_type { }; - template - struct __is_pointer_helper + /// is_pointer +#if __has_builtin(__is_pointer) + template + struct is_pointer + : public __bool_constant<__is_pointer(_Tp)> + { }; +#else + template + struct is_pointer : public false_type { }; + { }; template - struct __is_pointer_helper<_Tp*> + struct is_pointer<_Tp*> : public true_type { }; - /// is_pointer template - struct is_pointer - : public __is_pointer_helper<__remove_cv_t<_Tp>>::type - { }; + struct is_pointer<_Tp* const> + : public true_type { }; + + template + struct is_pointer<_Tp* volatile> + : public true_type { }; + + template + struct is_pointer<_Tp* const volatile> + : public true_type { }; +#endif /// is_lvalue_reference template @@ -3168,8 +3183,22 @@ template template inline constexpr bool is_array_v<_Tp[_Num]> = true; +#if __has_builtin(__is_pointer) +template + inline constexpr bool is_pointer_v = __is_pointer(_Tp); +#else +template + inline constexpr bool is_pointer_v = false; +template + inline constexpr bool is_pointer_v<_Tp*> = true; +template + inline constexpr bool is_pointer_v<_Tp* const> = true; template - inline constexpr bool is_pointer_v = is_pointer<_Tp>::value; + inline constexpr bool is_pointer_v<_Tp* volatile> = true; +template + inline constexpr bool is_pointer_v<_Tp* const volatile> = true; +#endif + template inline constexpr bool is_lvalue_reference_v = false; template