From patchwork Wed Mar 15 19:43:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Berke Yavas X-Patchwork-Id: 70408 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp86549wrt; Wed, 15 Mar 2023 12:44:15 -0700 (PDT) X-Google-Smtp-Source: AK7set/rWvQIA3ttUnJ/4bGEBPftSrwEfNZczZCQXc0Ave8Dl3hc/GzFlGG2oPpvHOvki61MNELs X-Received: by 2002:a17:907:3947:b0:92f:a0d5:211c with SMTP id sp7-20020a170907394700b0092fa0d5211cmr2143535ejc.35.1678909455479; Wed, 15 Mar 2023 12:44:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678909455; cv=none; d=google.com; s=arc-20160816; b=za0L+oUutRysabOWFT9Ft5tN6gbrCv80RGtbtHQSuKGtBpxonTlizYsbB0CqeEm+e3 suEe21uqFldAjz/PdPwqhFRf+IJ5YqLD0AIEI8Uo0SL/M5gPADSGFtXShIjh1Y5ULkdf EUbP31vG93XcHryYYxDmhXlXOKK2IrzcA3vqP9wxxLubHccK5KfmT1KzEuFuFK2X9TDV MctSrrlp39UkiTCk133dDMQgTYrmi4v1RJtWov4ZBRb1/tHW9xWXGkaO0Yy/a17KH9EI gIQp2LbBBQUUg+iTOXro6eJF3vY82BwijzNDH63w6jmLw0iIUsyVqK22z8eVCrDILZ60 HgLw== 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:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=q42+C3l/nsjessq+SuMSZkRWIcn8wilpsj93JESjM04=; b=0iSJ6xmLXZzOjgQQYpaCwkcsk5NgNFDhfTKmYq/yOPrECENA0mnJgdm8TTaho6jo3x zK8bLTjhfpjN45xnffLmc6H6AgbEvzcH7sH7xTYNGNTaFlgjHziiAfQvoapu09/HK93X EhFlHucFaZGAU7UhkiwU8i+9Imm0LL4tK1JdbR9YAy5FI2VbmYfC+qz0tdmqZtU7Gd09 Mgu7fX+n6qh2RGi4V+mQwhdu9tJ77nbYrcv9+oCK3N/LSInwsLzGlDHfOzb1DRh6Ylre 3c0A3bZc+NQTtjQv8e9+xvRMbP+CRYePQhMDFqUoXX0/chdLSOD2wUhteNtOsSLFMrQX fFww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gWuZc4X7; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id gj14-20020a170906e10e00b008c25e1c05desi6393245ejb.392.2023.03.15.12.44.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 12:44:15 -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=gWuZc4X7; 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 686AB385828D for ; Wed, 15 Mar 2023 19:44:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 686AB385828D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1678909454; bh=q42+C3l/nsjessq+SuMSZkRWIcn8wilpsj93JESjM04=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=gWuZc4X72DXev6gQkw+QZxC/yx41XjbNF0WU6jPbKseumFjZWoPRYWtLJeA2yrCNN Q/pIgim1D2s4ZfIV7RNSJmf6hygD+fzoU8PrA+wswQ5fLENZ7wyfhMQOqqRHnGP2Gn /mQWB7XCtSYItMsEdMNwKyc1/lqxpaAqovQTsrDU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by sourceware.org (Postfix) with ESMTPS id 801F43858C83 for ; Wed, 15 Mar 2023 19:43:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 801F43858C83 Received: by mail-ed1-x535.google.com with SMTP id eh3so23958668edb.11 for ; Wed, 15 Mar 2023 12:43:29 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678909407; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=q42+C3l/nsjessq+SuMSZkRWIcn8wilpsj93JESjM04=; b=ghuvIeYnmm2jEtEk79mI6Toi+ryRwp3yEgzBvTRgkoIkMDptbT7nU9z/VTCnt7MU/v H0Xz6AVTo0GS9kac0TvqnTcKiscDr++taEqiPN6+XDPsK2+i5u+bp2mKgoehs2DlSQ8H OFGlxckH+VvYfSY2zE8g/2NTBJdkUZJR5ALXmlXPLocafGE0npaYgTUxPBoYPECbUy2Z aG0sGesoj4As9gO6dXNsjCzwr1P5MCLnpiOhX8NuDVjTRav0WE/HwHrLVkMphJDtODXp HypR2ztV7JQObPIyeZtfig0uUGugCIVZl89ZWn2xHXktHEfpJUeWpi9DAc44ZXAu+WTY 8F/w== X-Gm-Message-State: AO0yUKUihL0ycvyba2ICPv4wAPblSQHh5xVirSJZL0Aq5V9K3ECWlKQy VL9vZE8n7LqQWE1V3x2opUziX3AsNq5HQg== X-Received: by 2002:aa7:d943:0:b0:4fb:fd9f:7375 with SMTP id l3-20020aa7d943000000b004fbfd9f7375mr3970554eds.2.1678909407416; Wed, 15 Mar 2023 12:43:27 -0700 (PDT) Received: from 192.168.1.35 ([188.119.40.52]) by smtp.gmail.com with ESMTPSA id a28-20020a50c31c000000b004af6c5f1805sm2926624edb.52.2023.03.15.12.43.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 12:43:26 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: Berke Subject: [PATCH] compiler built in is_scalar, use built-in is_scalar in libstdc++ std::is_scalar Date: Wed, 15 Mar 2023 22:43:24 +0300 Message-Id: <20230315194324.1930746-1-iamberkeyavas@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, 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: Berke Yavas via Gcc-patches From: Berke Yavas Reply-To: Berke Yavas 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?1760464161515221736?= X-GMAIL-MSGID: =?utf-8?q?1760464161515221736?= From: Berke Signed-off-by: Berke Yavas --- gcc/cp/constraint.cc | 3 +++ gcc/cp/cp-trait.def | 1 + gcc/cp/cxx-pretty-print.cc | 3 ++- gcc/cp/parser.cc | 1 + gcc/cp/semantics.cc | 4 ++++ gcc/testsuite/g++.dg/ext/has-builtin-1.C | 4 ++++ gcc/testsuite/g++.dg/ext/is_scalar.C | 21 +++++++++++++++++++++ gcc/testsuite/g++.dg/tm/pr46567.C | 10 +++++----- gcc/testsuite/g++.dg/torture/pr57107.C | 4 ++-- libstdc++-v3/include/bits/cpp_type_traits.h | 8 ++++---- libstdc++-v3/include/bits/stl_algobase.h | 8 ++++---- libstdc++-v3/include/bits/valarray_array.h | 2 +- libstdc++-v3/include/std/type_traits | 7 +++++++ 13 files changed, 59 insertions(+), 17 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_scalar.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 9374327008b..f799ba2efd5 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3747,6 +3747,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_SCALAR: + inform(loc, " %qT is not a scalar 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 823899a26c5..8dace289e88 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_SCALAR, "__is_scalar", 1) DEFTRAIT_EXPR (REF_CONSTRUCTS_FROM_TEMPORARY, "__reference_constructs_from_temporary", 2) DEFTRAIT_EXPR (REF_CONVERTS_FROM_TEMPORARY, "__reference_converts_from_temporary", 2) diff --git a/gcc/cp/cxx-pretty-print.cc b/gcc/cp/cxx-pretty-print.cc index bea52a608f1..a79359430a5 100644 --- a/gcc/cp/cxx-pretty-print.cc +++ b/gcc/cp/cxx-pretty-print.cc @@ -437,7 +437,8 @@ pp_cxx_userdef_literal (cxx_pretty_printer *pp, tree t) __is_polymorphic ( type-id ) __is_std_layout ( type-id ) __is_trivial ( type-id ) - __is_union ( type-id ) */ + __is_union ( type-id ) + __is_scalar ( type-id ) */ void cxx_pretty_printer::primary_expression (tree t) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index b00a6cd5b8b..8465d4fbcdb 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -5577,6 +5577,7 @@ cp_parser_fold_expression (cp_parser *parser, tree expr1) __is_std_layout ( type-id ) __is_trivial ( type-id ) __is_union ( type-id ) + __is_scalar ( type-id ) Objective-C++ Extension: diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index db982d594e6..81b13d1ae5c 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12025,6 +12025,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: return type_code1 == UNION_TYPE; + case CPTK_IS_SCALAR: + return SCALAR_TYPE_P (type1); + case CPTK_IS_ASSIGNABLE: return is_xible (MODIFY_EXPR, type1, type2); @@ -12190,6 +12193,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_CLASS: case CPTK_IS_ENUM: case CPTK_IS_UNION: + case CPTK_IS_SCALAR: case CPTK_IS_SAME: break; diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C index f343e153e56..4bf06a7a438 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -146,3 +146,7 @@ #if !__has_builtin (__remove_cvref) # error "__has_builtin (__remove_cvref) failed" #endif +#if !__has_builtin (__is_scalar) +# error "__has_builtin (__is_scalar) failed" +#endif + diff --git a/gcc/testsuite/g++.dg/ext/is_scalar.C b/gcc/testsuite/g++.dg/ext/is_scalar.C new file mode 100644 index 00000000000..1d58f6ec475 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_scalar.C @@ -0,0 +1,21 @@ +// { dg-do compile { target c++11 } } + +#define SA(X) static_assert((X),#X) + +struct S { int m; }; + +enum class E { + e +}; + +int main() { + char* pNull= nullptr; + + SA(__is_scalar(decltype(pNull))); + SA(__is_scalar(int)); + SA(__is_scalar(double)); + SA(__is_scalar(E)); + SA(__is_scalar(char const *)); + SA(!__is_scalar(struct S)); + return 0; +} \ No newline at end of file diff --git a/gcc/testsuite/g++.dg/tm/pr46567.C b/gcc/testsuite/g++.dg/tm/pr46567.C index 6d791484448..760c7fd6cab 100644 --- a/gcc/testsuite/g++.dg/tm/pr46567.C +++ b/gcc/testsuite/g++.dg/tm/pr46567.C @@ -225,7 +225,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { : public __traitor<__is_void<_Tp>, __is_arithmetic<_Tp> > { }; template - struct __is_scalar + struct __is_arith_or_ptr : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > { }; template @@ -1325,7 +1325,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if::__value, void>::__type + __gnu_cxx::__enable_if::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1334,7 +1334,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __gnu_cxx::__enable_if<__is_arith_or_ptr<_Tp>::__value, void>::__type __fill_a(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1362,7 +1362,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { for (; __n > 0; --__n, ++__first) @@ -1371,7 +1371,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { } template inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if<__is_arith_or_ptr<_Tp>::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { const _Tp __tmp = __value; diff --git a/gcc/testsuite/g++.dg/torture/pr57107.C b/gcc/testsuite/g++.dg/torture/pr57107.C index 4dbd32bd298..42ec0c8d350 100644 --- a/gcc/testsuite/g++.dg/torture/pr57107.C +++ b/gcc/testsuite/g++.dg/torture/pr57107.C @@ -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_arith_or_ptr : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > { }; } namespace __gnu_cxx __attribute__ ((__visibility__ ("default"))) { @@ -54,7 +54,7 @@ namespace std __attribute__ ((__visibility__ ("default"))) { }; template inline typename _Niter_base<_Iterator>::iterator_type __niter_base(_Iterator __it) { } - template inline typename __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { + template inline typename __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { for (__decltype(__n + 0) __niter = __n; __niter > 0; --__niter, ++__first) *__first = __value; diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index 4312f32a4e0..54a157ff960 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -385,11 +385,11 @@ __INT_N(__GLIBCXX_TYPE_INT_N_3) : public __traitor<__is_integer<_Tp>, __is_floating<_Tp> > { }; - // - // A scalar type is an arithmetic type or a pointer type - // +// // +// // A scalar type is an arithmetic type or a pointer type +// // template - struct __is_scalar + struct __is_arith_or_ptr : public __traitor<__is_arithmetic<_Tp>, __is_pointer<_Tp> > { }; diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 4a6f8195d98..3922386f834 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -911,7 +911,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if::__value, void>::__type + __gnu_cxx::__enable_if::__value, void>::__type __fill_a1(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -922,7 +922,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __gnu_cxx::__enable_if<__is_arith_or_ptr<_Tp>::__value, void>::__type __fill_a1(_ForwardIterator __first, _ForwardIterator __last, const _Tp& __value) { @@ -1060,7 +1060,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value) { for (; __n > 0; --__n, (void) ++__first) @@ -1071,7 +1071,7 @@ _GLIBCXX_END_NAMESPACE_CONTAINER template _GLIBCXX20_CONSTEXPR inline typename - __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type + __gnu_cxx::__enable_if<__is_arith_or_ptr<_Tp>::__value, _OutputIterator>::__type __fill_n_a1(_OutputIterator __first, _Size __n, const _Tp& __value) { const _Tp __tmp = __value; diff --git a/libstdc++-v3/include/bits/valarray_array.h b/libstdc++-v3/include/bits/valarray_array.h index 222fd5fd900..af259383648 100644 --- a/libstdc++-v3/include/bits/valarray_array.h +++ b/libstdc++-v3/include/bits/valarray_array.h @@ -90,7 +90,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION inline void __valarray_default_construct(_Tp* __b, _Tp* __e) { - _Array_default_ctor<_Tp, __is_scalar<_Tp>::__value>::_S_do_it(__b, __e); + _Array_default_ctor<_Tp, __is_arith_or_ptr<_Tp>::__value>::_S_do_it(__b, __e); } // Turn a raw-memory into an array of _Tp filled with __t diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 2bd607a8b8f..2dfc79cbe01 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -678,11 +678,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_member_pointer; /// is_scalar +#if __has_builtin(__is_scalar) + template + struct is_scalar + : public __bool_constant<__is_scalar(_Tp)> + { }; +#else template struct is_scalar : public __or_, is_enum<_Tp>, is_pointer<_Tp>, is_member_pointer<_Tp>, is_null_pointer<_Tp>>::type { }; +#endif /// is_compound template