From patchwork Thu Jul 13 01:43:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119466 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1530291vqm; Wed, 12 Jul 2023 18:45:43 -0700 (PDT) X-Google-Smtp-Source: APBJJlHt0DB2nQAYGIP34LTrBdh2guEcta8Fe+9EpKWOxwM+nXmuiPOsGNbY8tvyF0Pq9ryrJWgQ X-Received: by 2002:a05:6402:8d0:b0:51e:1c18:dd99 with SMTP id d16-20020a05640208d000b0051e1c18dd99mr393280edz.38.1689212743000; Wed, 12 Jul 2023 18:45:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689212742; cv=none; d=google.com; s=arc-20160816; b=hZfm3GHQtr9oG1YG0n9MAupKTO95JEyNZJTYrs+0uNAfLGFhsaZO/0BE9iBIpnqYwF MlG8fY4veZFRmteY7shLaPg4Byw3cX7kDTYcAK45uzGkXt+Lp7Q2ve5hTG/5dlTnn4DX 2vswuDRXP9T+RamyyiQhyGgDdYoq+wjAgmPA8VQol1cOUe6m2aDVo6PbCMLA1YnQPKdu QjLNduch+qGnoWnT+REh6Aew9Tt5yVHCjzpw39Sx74HujRX0QH+dmiUxHyqG0BYlpC0p V46V1Qm8GgJ0CZvU7l6zZXZ7NVXaqQ7A55XytUdhMxvBZVViAo169+/C5xVUTdSUEioh FPrQ== 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=G+a1hu9uMNewwXqXPW5y4AN2bixWbwfBdri3vIH6CH0=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=g+UU1wd6tHlDUi7NDtdJE/khcCO7XpNvt59MnPoO/NOq17QDQBNta89Qvr2VaDd7Ir 2+og9OXtYf8FlZY7gw3n9pwKATAyUMVKa6b2roeUpk2j5EVc3WY6peoEs4Heta8TX2BA QxWAkuWP/Z0/U8MJaByjDX/poIR2nzzRRlC+d/k4S6EohSnmzsNZAYTw3m+d8qCUIpf4 THjQ3/dM5pDGZhkMJ4Thn8AJSolcFfz26XAypYS+AnJFD3cRjn5q+FYPPTYNbBPgKGtB btrynIvYWqMEhGoKxCdLipFK8C7m3sJrmi2ysH42ihiASVgKsajkURe6bf4cRgxAomOQ WWKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=vuwORlDP; 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 c8-20020aa7df08000000b0051ddfb3c937si6631215edy.3.2023.07.12.18.45.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 18:45:42 -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=vuwORlDP; 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 014B53857034 for ; Thu, 13 Jul 2023 01:44:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 014B53857034 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689212691; bh=G+a1hu9uMNewwXqXPW5y4AN2bixWbwfBdri3vIH6CH0=; 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=vuwORlDPBwoUif2oR5UleBuuBX8apiNhna7Cz4lggiqKRr8Wo3lpUBiBrJ/7Dv3Ix sqZBKPztTHgNTrfVtxkmD9KLmW2AlNMyjlbthEpijO9t7BW4RhrJchoftC1eJLnChR y1iwtauE8JdCJ/kj1hXtgLycaurCbbshHivlA1do= 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 3D0933858C74; Thu, 13 Jul 2023 01:44:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3D0933858C74 Received: from pps.filterd (m0247471.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36D1YOAk001515; Thu, 13 Jul 2023 01:43:58 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rt1xhjnqu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 01:43:58 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout24.cac.washington.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36D1hqPV002426 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 18:43:52 -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 36D1hqic021486 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 18:43:52 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v2 1/2] c++, libstdc++: Implement __is_signed built-in trait Date: Wed, 12 Jul 2023 18:43:50 -0700 Message-ID: <20230713014351.6442-1-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: wEQnFDhQpYOmJMiXClrSF8AQkMIroaDA X-Proofpoint-GUID: wEQnFDhQpYOmJMiXClrSF8AQkMIroaDA 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 adultscore=0 suspectscore=0 impostorscore=0 clxscore=1034 mlxlogscore=999 malwarescore=0 phishscore=0 spamscore=0 bulkscore=0 lowpriorityscore=0 priorityscore=1501 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307130014 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: 1771267941208989250 X-GMAIL-MSGID: 1771267941208989250 This patch implements built-in trait for std::is_signed. gcc/cp/ChangeLog: * cp-trait.def: Define __is_signed. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_SIGNED. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_signed. * g++.dg/ext/is_signed.C: New test. * g++.dg/tm/pr46567.C (__is_signed): Rename to ... (__is_signed_type): ... this. libstdc++-v3/ChangeLog: * include/ext/numeric_traits.h (__is_signed): Rename to ... (__is_signed_type): ... this. * include/bits/charconv.h: Use __is_signed_type instead. * include/bits/locale_facets.tcc: Likewise. * include/bits/uniform_int_dist.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_signed.C | 47 ++++++++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 12 ++--- libstdc++-v3/include/bits/charconv.h | 2 +- libstdc++-v3/include/bits/locale_facets.tcc | 6 +-- libstdc++-v3/include/bits/uniform_int_dist.h | 4 +- libstdc++-v3/include/ext/numeric_traits.h | 18 ++++---- 10 files changed, 79 insertions(+), 21 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_signed.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 8cf0f2d0974..73fcbfe39e8 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_SIGNED: + inform (loc, " %qT is not a signed type", 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..576d5528d05 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_SIGNED, "__is_signed", 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..17aad992f96 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_SIGNED: + return ARITHMETIC_TYPE_P (type1) && TYPE_SIGN (type1) == SIGNED; + 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_SIGNED: 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..a43202d0d59 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_signed) +# error "__has_builtin (__is_signed) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_signed.C b/gcc/testsuite/g++.dg/ext/is_signed.C new file mode 100644 index 00000000000..a04b548105d --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_signed.C @@ -0,0 +1,47 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, X, expect) \ + SA(TRAIT(X) == expect); \ + SA(TRAIT(const X) == expect); \ + SA(TRAIT(volatile X) == expect); \ + SA(TRAIT(const volatile X) == expect) + +SA_TEST_CATEGORY(__is_signed, void, false); + +SA_TEST_CATEGORY(__is_signed, bool, bool(-1) < bool(0)); +SA_TEST_CATEGORY(__is_signed, char, char(-1) < char(0)); +SA_TEST_CATEGORY(__is_signed, signed char, true); +SA_TEST_CATEGORY(__is_signed, unsigned char, false); +SA_TEST_CATEGORY(__is_signed, wchar_t, wchar_t(-1) < wchar_t(0)); +SA_TEST_CATEGORY(__is_signed, short, true); +SA_TEST_CATEGORY(__is_signed, unsigned short, false); +SA_TEST_CATEGORY(__is_signed, int, true); +SA_TEST_CATEGORY(__is_signed, unsigned int, false); +SA_TEST_CATEGORY(__is_signed, long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long, false); +SA_TEST_CATEGORY(__is_signed, long long, true); +SA_TEST_CATEGORY(__is_signed, unsigned long long, false); + +SA_TEST_CATEGORY(__is_signed, float, true); +SA_TEST_CATEGORY(__is_signed, double, true); +SA_TEST_CATEGORY(__is_signed, long double, true); + +#ifndef __STRICT_ANSI__ +// GNU Extensions. +#ifdef __SIZEOF_INT128__ +SA_TEST_CATEGORY(__is_signed, __int128, true); +SA_TEST_CATEGORY(__is_signed, unsigned __int128, false); +#endif + +#ifdef _GLIBCXX_USE_FLOAT128 +SA_TEST_CATEGORY(__is_signed, __float128, true); +#endif +#endif + +// Sanity check. +SA_TEST_CATEGORY(__is_signed, ClassType, false); diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 6d791484448..38ddc1cb875 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -403,7 +403,7 @@ namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { { static const _Value __min = (((_Value)(-1) < 0) ? (_Value)1 << (sizeof(_Value) * 8 - ((_Value)(-1) < 0)) : (_Value)0); static const _Value __max = (((_Value)(-1) < 0) ? (((((_Value)1 << ((sizeof(_Value) * 8 - ((_Value)(-1) < 0)) - 1)) - 1) << 1) + 1) : ~(_Value)0); - static const bool __is_signed = ((_Value)(-1) < 0); + static const bool __is_signed_type = ((_Value)(-1) < 0); static const int __digits = (sizeof(_Value) * 8 - ((_Value)(-1) < 0)); }; template @@ -411,21 +411,21 @@ namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { template const _Value __numeric_traits_integer<_Value>::__max; template - const bool __numeric_traits_integer<_Value>::__is_signed; + const bool __numeric_traits_integer<_Value>::__is_signed_type; template const int __numeric_traits_integer<_Value>::__digits; template struct __numeric_traits_floating { static const int __max_digits10 = (2 + (std::__are_same<_Value, float>::__value ? 24 : std::__are_same<_Value, double>::__value ? 53 : 64) * 3010 / 10000); - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = (std::__are_same<_Value, float>::__value ? 6 : std::__are_same<_Value, double>::__value ? 15 : 18); static const int __max_exponent10 = (std::__are_same<_Value, float>::__value ? 38 : std::__are_same<_Value, double>::__value ? 308 : 4932); }; template const int __numeric_traits_floating<_Value>::__max_digits10; template - const bool __numeric_traits_floating<_Value>::__is_signed; + const bool __numeric_traits_floating<_Value>::__is_signed_type; template const int __numeric_traits_floating<_Value>::__digits10; template @@ -1513,8 +1513,8 @@ namespace std __attribute__ ((__visibility__ ("default"))) { typedef typename iterator_traits<_II2>::value_type _ValueType2; const bool __simple = (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value - && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed - && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed + && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed_type + && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed_type && __is_pointer<_II1>::__value && __is_pointer<_II2>::__value); return std::__lexicographical_compare<__simple>::__lc(__first1, __last1, diff --git a/libstdc++-v3/include/bits/charconv.h b/libstdc++-v3/include/bits/charconv.h index 20da8303f7a..1acf1e46e4c 100644 --- a/libstdc++-v3/include/bits/charconv.h +++ b/libstdc++-v3/include/bits/charconv.h @@ -46,7 +46,7 @@ namespace __detail // This accepts 128-bit integers even in strict mode. template constexpr bool __integer_to_chars_is_unsigned - = ! __gnu_cxx::__int_traits<_Tp>::__is_signed; + = ! __gnu_cxx::__int_traits<_Tp>::__is_signed_type; #endif // Generic implementation for arbitrary bases. diff --git a/libstdc++-v3/include/bits/locale_facets.tcc b/libstdc++-v3/include/bits/locale_facets.tcc index 6bfff7d6289..38a6920abe9 100644 --- a/libstdc++-v3/include/bits/locale_facets.tcc +++ b/libstdc++-v3/include/bits/locale_facets.tcc @@ -470,7 +470,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL bool __testfail = false; bool __testoverflow = false; const __unsigned_type __max = - (__negative && __num_traits::__is_signed) + (__negative && __num_traits::__is_signed_type) ? -static_cast<__unsigned_type>(__num_traits::__min) : __num_traits::__max; const __unsigned_type __smax = __max / __base; @@ -573,7 +573,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL } else if (__testoverflow) { - if (__negative && __num_traits::__is_signed) + if (__negative && __num_traits::__is_signed_type) __v = __num_traits::__min; else __v = __num_traits::__max; @@ -914,7 +914,7 @@ _GLIBCXX_BEGIN_NAMESPACE_LDBL if (__v >= 0) { if (bool(__flags & ios_base::showpos) - && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed) + && __gnu_cxx::__numeric_traits<_ValueT>::__is_signed_type) *--__cs = __lit[__num_base::_S_oplus], ++__len; } else diff --git a/libstdc++-v3/include/bits/uniform_int_dist.h b/libstdc++-v3/include/bits/uniform_int_dist.h index 7ccf930a6d4..73b808e57f3 100644 --- a/libstdc++-v3/include/bits/uniform_int_dist.h +++ b/libstdc++-v3/include/bits/uniform_int_dist.h @@ -258,8 +258,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { using _Up_traits = __gnu_cxx::__int_traits<_Up>; using _Wp_traits = __gnu_cxx::__int_traits<_Wp>; - static_assert(!_Up_traits::__is_signed, "U must be unsigned"); - static_assert(!_Wp_traits::__is_signed, "W must be unsigned"); + static_assert(!_Up_traits::__is_signed_type, "U must be unsigned"); + static_assert(!_Wp_traits::__is_signed_type, "W must be unsigned"); static_assert(_Wp_traits::__digits == (2 * _Up_traits::__digits), "W must be twice as wide as U"); diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h index dcbc2d12927..c618f211775 100644 --- a/libstdc++-v3/include/ext/numeric_traits.h +++ b/libstdc++-v3/include/ext/numeric_traits.h @@ -67,15 +67,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // NB: these two are also available in std::numeric_limits as compile // time constants, but is big and we can avoid including it. - static const bool __is_signed = (_Value)(-1) < 0; + static const bool __is_signed_type = (_Value)(-1) < 0; static const int __digits - = __is_integer_nonstrict<_Value>::__width - __is_signed; + = __is_integer_nonstrict<_Value>::__width - __is_signed_type; // The initializers must be constants so that __max and __min are too. - static const _Value __max = __is_signed + static const _Value __max = __is_signed_type ? (((((_Value)1 << (__digits - 1)) - 1) << 1) + 1) : ~(_Value)0; - static const _Value __min = __is_signed ? -__max - 1 : (_Value)0; + static const _Value __min = __is_signed_type ? -__max - 1 : (_Value)0; }; template @@ -85,7 +85,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const _Value __numeric_traits_integer<_Value>::__max; template - const bool __numeric_traits_integer<_Value>::__is_signed; + const bool __numeric_traits_integer<_Value>::__is_signed_type; template const int __numeric_traits_integer<_Value>::__digits; @@ -161,7 +161,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static const int __max_digits10 = __glibcxx_max_digits10(_Value); // See above comment... - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = __glibcxx_digits10(_Value); static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); }; @@ -170,7 +170,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION const int __numeric_traits_floating<_Value>::__max_digits10; template - const bool __numeric_traits_floating<_Value>::__is_signed; + const bool __numeric_traits_floating<_Value>::__is_signed_type; template const int __numeric_traits_floating<_Value>::__digits10; @@ -210,7 +210,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __numeric_traits_floating<__ibm128> { static const int __max_digits10 = 33; - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = 31; static const int __max_exponent10 = 308; }; @@ -224,7 +224,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct __numeric_traits_floating<__ieee128> { static const int __max_digits10 = 36; - static const bool __is_signed = true; + static const bool __is_signed_type = true; static const int __digits10 = 33; static const int __max_exponent10 = 4932; }; From patchwork Thu Jul 13 01:43:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119467 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1530569vqm; Wed, 12 Jul 2023 18:46:36 -0700 (PDT) X-Google-Smtp-Source: APBJJlHY+I58XUX2XBRR+ZybmcQa2e2JTxP6wMT98C5FN5LEiXP8BzYddUBqzezZQ7jt6kfkBDE1 X-Received: by 2002:a05:651c:d6:b0:2b7:310:65da with SMTP id 22-20020a05651c00d600b002b7031065damr64660ljr.24.1689212795809; Wed, 12 Jul 2023 18:46:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689212795; cv=none; d=google.com; s=arc-20160816; b=ISy4/5ApnePgLH9M/4D1sPrh/+ILqyKMlaRtQLIAi6KlSWecaHZGFa84/UwDrfSyMi WoLgB5bylH5+62w9MrQpXwLVEubUsq91iWYHRH0R7LX3yxrJ/Dmjmab4Gf3BQKklu7J6 fTdsQXOc/wf0Q6ZqTGPMDOZe7FYmnzXUH4pOGewJess3Gy2eASiEt8yUx2vWlGNtcCOQ Z6/gsRR3s1IOXWEbnoIACb139eb79s4B1drXVL3mQsoqYCM4xzvEkGHcCb5B7473Q8Se xYXjr3zptCtwaCe8vz7NcYnm8oAWHSWEAykiHaoo4bmWkSoe8kOe//9azcjw+EDdNg4V v5Bg== 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=eWjAAZqIqkmtwYHumKYur5yTt+6Lg+HYF+9OD71YcMw=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=A1ZEcmHVG5Kvhwg+2MVTVEehU+rc6YTxXpVU6wp9ffNgGsfE2D4S0wKCJ4Pas5AYxI 6zr6LLIFCdQowVOpDPFRKAJ+opvJ51QCpW+GZsP4mTmwfb2bOZl7gTjegi3xRF2z+Gxl 5lMOENlWCD8Rfq0IFoPKjHlnHs7S2pfQvaYi45/5+ZZPI1KhHofx84i5Q6npswJ73ehM tMrUgyquHaGQMT72aTezZ/FTQYTE6piQ27R256euhteMsfHAKRby7QHkXB6+7XFFTVsg QEteOo29s2zcWFLDADtCznE9tnVXMsfzUs6UHFYBJyDJi5k5+KQk4bNUbU1gXe40DTNO Bj6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=eUlTqv4g; 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 t5-20020a170906948500b00988c81e980dsi6282753ejx.1039.2023.07.12.18.46.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 18:46:35 -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=eUlTqv4g; 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 CCD32385B51F for ; Thu, 13 Jul 2023 01:45:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCD32385B51F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689212752; bh=eWjAAZqIqkmtwYHumKYur5yTt+6Lg+HYF+9OD71YcMw=; 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=eUlTqv4grOBr+ZlvieqASz+B3E8aHmSjlj7S2+s/mhEgzE6TOhDnBMiDuE9poJUhq 5ZHw29N9ivwMW8WZlNms4NqFXH0jyF6FofHsarYiczgDdmFulIzBgc4yGq1XNwOOs2 NDFpvv/5GpDlW+Ar0pV1T0cKMicG3j7LUaK/jYcU= 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 691D33856DF1; Thu, 13 Jul 2023 01:45:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 691D33856DF1 Received: from pps.filterd (m0247478.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36D1Tl4V013357; Thu, 13 Jul 2023 01:45:03 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rt1s8amxc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 01:45:02 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout21.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36D1idaO030028 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 18:44:39 -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 36D1hqid021486 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 18:44:39 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v2 2/2] libstdc++: Use new built-in trait __is_signed Date: Wed, 12 Jul 2023 18:43:51 -0700 Message-ID: <20230713014351.6442-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713014351.6442-1-kmatsui@gcc.gnu.org> References: <20230713014351.6442-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: cwVHZ6SYtQTewo4TmGzxTSLPeaNVB1H_ X-Proofpoint-ORIG-GUID: cwVHZ6SYtQTewo4TmGzxTSLPeaNVB1H_ 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 bulkscore=0 mlxlogscore=926 impostorscore=0 clxscore=1034 spamscore=0 lowpriorityscore=0 adultscore=0 priorityscore=1501 phishscore=0 mlxscore=0 suspectscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307130014 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: 1771267996424113647 X-GMAIL-MSGID: 1771267996424113647 This patch lets libstdc++ use new built-in trait __is_signed. libstdc++-v3/ChangeLog: * include/std/type_traits (is_signed): Use __is_signed built-in trait. (is_signed_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 0e7a9c9c7f3..23ab5a4b1e5 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -865,6 +865,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION : public __bool_constant<__is_abstract(_Tp)> { }; + /// is_signed +#if __has_builtin(__is_signed) + template + struct is_signed + : public __bool_constant<__is_signed(_Tp)> + { }; +#else /// @cond undocumented template::value> @@ -877,11 +884,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// @endcond - /// is_signed template struct is_signed : public __is_signed_helper<_Tp>::type { }; +#endif /// is_unsigned template @@ -3240,8 +3247,14 @@ template template inline constexpr bool is_final_v = __is_final(_Tp); +#if __has_builtin(__is_signed) +template + inline constexpr bool is_signed_v = __is_signed(_Tp); +#else template inline constexpr bool is_signed_v = is_signed<_Tp>::value; +#endif + template inline constexpr bool is_unsigned_v = is_unsigned<_Tp>::value;