From patchwork Thu Jul 13 02:33:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119483 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1548469vqm; Wed, 12 Jul 2023 19:41:18 -0700 (PDT) X-Google-Smtp-Source: APBJJlHkA6Ja38AkPm5xBPmftBjfZZL+r1AROdqZZHAaq/yARlooYApL6akEHNKBjjbfnTkDIzpM X-Received: by 2002:ac2:5f4d:0:b0:4fb:89f2:278e with SMTP id 13-20020ac25f4d000000b004fb89f2278emr24918lfz.68.1689216077818; Wed, 12 Jul 2023 19:41:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689216077; cv=none; d=google.com; s=arc-20160816; b=e52mGSjH1H594iHqCzRE943JsjXqE4jSVVL4bw3w3RGRU/0mHvSKKsAGCTprmJ+PzZ ZmVTQ9pirobi/tfcQHB/Qcsz5Pp7UhA84WmGdCUhhufKsyda0atUYHcUUJxju0WWZtZg PHW6xKaNe2MWeunccm0f6QPS6ki6GtVXBYQYzO6Q8ZhCg5pxCrySJXGS7Iv7x6KjJgJt J8SjIXNAFa5MR5mLGp1qtRZbyUM7GFXnejAMgYoQaX+OtQU11qwK2BfIYR6EkqeIBsjM n/DCSAKKPhWP8NSqEDSOE9pK4dvz/xpHBd6ewgphlDO4z43ZCJJUBkLdCthfwkGWMfLM po7Q== 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=FmypBWY4c1bybaYdnxQJDuizVfI6in3joSwYgA3GX4g=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=N2WxD2WFCDkK2fXfR3fou4tEbEH+HR0eZ1QXpdthSkBQd+Jt1NH+9M0ppGtIOHKnke wm5mFqqLMlzmei+8VLXmlrEgnD8xaOlKR0pQEYkapeI3/xthBPTB2PrFOSChjo9MHaCy nyRl0m8NIAGb4nlpjuqqUj1/1ScxhwlvQ0FvxLUgZ6oMz+8xpCUngnqVUWm4wenK2iNw 2/8oursEAtdqpHNko3jxjdoJ7bzoTGMTrrix5bz6mJn1odgkQvJCIW6tI9N4Yw/JXaZd ncPvgMACbcR/gb9khMoxI5thFmQzjYwvCqtVpANk6/eAExgdaJMux4S0oZNtXE0zRu+o +9yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=G1VfcflE; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u7-20020a05640207c700b0051bc6e5d1bbsi6091936edy.79.2023.07.12.19.41.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 19:41:17 -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=G1VfcflE; 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 62FF43858C74 for ; Thu, 13 Jul 2023 02:40:21 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 62FF43858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689216021; bh=FmypBWY4c1bybaYdnxQJDuizVfI6in3joSwYgA3GX4g=; 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=G1VfcflEzdv2QkACHkTLcRe47gKionT3293jhpmY7G7lVqHwrdmFDlxM7yi97B30I 7JGkjuHx3FafR6MGfFkI8WSnU9eeapAgG4oP+lBLr34Br53+miFKf51V015MpiCJ1g 7jYij21fPsGZrpvJ4zXKYWg+v0KxeBXw5Jf9s2sI= 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 3530F3857726; Thu, 13 Jul 2023 02:38:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3530F3857726 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 36D2a2YV024725; Thu, 13 Jul 2023 02:38:39 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rt1s8asx2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 02:38:38 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36D2cQim018703 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 19:38:27 -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 36D2bY7E020817 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 19:38:26 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v10 1/5] c++: Implement __is_reference built-in trait Date: Wed, 12 Jul 2023 19:33:35 -0700 Message-ID: <20230713023731.15571-2-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713023731.15571-1-kmatsui@gcc.gnu.org> References: <20230708051137.63707-1-kmatsui@gcc.gnu.org> <20230713023731.15571-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Teb4jO1sWwJlHTN5DeQGjAksJK7PlUeG X-Proofpoint-ORIG-GUID: Teb4jO1sWwJlHTN5DeQGjAksJK7PlUeG 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=913 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-2307130021 X-Spam-Status: No, score=-12.9 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: 1771271437745305516 X-GMAIL-MSGID: 1771271437745305516 This patch implements built-in trait for std::is_reference. gcc/cp/ChangeLog: * cp-trait.def: Define __is_reference. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_REFERENCE. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_reference. * g++.dg/ext/is_reference.C: New test. 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_reference.C | 34 ++++++++++++++++++++++++ 5 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_reference.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 8cf0f2d0974..f6951ee2670 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3705,6 +3705,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_HAS_VIRTUAL_DESTRUCTOR: inform (loc, " %qT does not have a virtual destructor", t1); break; + case CPTK_IS_REFERENCE: + inform (loc, " %qT is not a reference", t1); + break; case CPTK_IS_ABSTRACT: inform (loc, " %qT is not an abstract class", t1); break; diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def index 8b7fece0cc8..1e3310cd682 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -67,6 +67,7 @@ DEFTRAIT_EXPR (IS_CONVERTIBLE, "__is_convertible", 2) DEFTRAIT_EXPR (IS_EMPTY, "__is_empty", 1) DEFTRAIT_EXPR (IS_ENUM, "__is_enum", 1) DEFTRAIT_EXPR (IS_FINAL, "__is_final", 1) +DEFTRAIT_EXPR (IS_REFERENCE, "__is_reference", 1) DEFTRAIT_EXPR (IS_LAYOUT_COMPATIBLE, "__is_layout_compatible", 2) DEFTRAIT_EXPR (IS_LITERAL_TYPE, "__is_literal_type", 1) DEFTRAIT_EXPR (IS_NOTHROW_ASSIGNABLE, "__is_nothrow_assignable", 2) diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index a2e74a5d2c7..2f37bc353a1 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12075,6 +12075,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); + case CPTK_IS_REFERENCE: + return type_code1 == REFERENCE_TYPE; + case CPTK_IS_LAYOUT_COMPATIBLE: return layout_compatible_type_p (type1, type2); @@ -12289,6 +12292,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_REFERENCE: 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..b697673790c 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_reference) +# error "__has_builtin (__is_reference) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_reference.C b/gcc/testsuite/g++.dg/ext/is_reference.C new file mode 100644 index 00000000000..b5ce4db7afd --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_reference.C @@ -0,0 +1,34 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +// Positive tests. +SA_TEST_CATEGORY(__is_reference, int&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&, true); +SA(__is_reference(int(&)(int))); +SA_TEST_CATEGORY(__is_reference, int&&, true); +SA_TEST_CATEGORY(__is_reference, ClassType&&, true); +SA(__is_reference(int(&&)(int))); +SA_TEST_CATEGORY(__is_reference, IncompleteClass&, true); + +// Negative tests +SA_TEST_CATEGORY(__is_reference, void, false); +SA_TEST_CATEGORY(__is_reference, int*, false); +SA_TEST_CATEGORY(__is_reference, int[3], false); +SA(!__is_reference(int(int))); +SA(!__is_reference(int(*const)(int))); +SA(!__is_reference(int(*volatile)(int))); +SA(!__is_reference(int(*const volatile)(int))); + +// Sanity check. +SA_TEST_CATEGORY(__is_reference, ClassType, false); +SA_TEST_CATEGORY(__is_reference, IncompleteClass, false); From patchwork Thu Jul 13 02:33:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119482 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1548288vqm; Wed, 12 Jul 2023 19:40:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlFWqm9+1doj8Xp/KLfKgKh9hdMPuuLs4vIHF8teuORTL3UVFh1HQ3gsNj3IIPz2txp1a4Dn X-Received: by 2002:a17:906:10d7:b0:987:4e89:577f with SMTP id v23-20020a17090610d700b009874e89577fmr155770ejv.24.1689216044075; Wed, 12 Jul 2023 19:40:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689216044; cv=none; d=google.com; s=arc-20160816; b=04rwlMlL3n2zm76d6m/LXsMguuHjOPld6wyA99dyAKngY3yyzQb9EnhpQeXvdMcqQz ufIhVBZ/VVuNDhdQMHj9xNAg3adQMeLpiJr01mBbU+bGVNKoxaC+DbUReJS1JhqEyTL6 PKDCob1VsHMCvplVHiLyBvo2/ujNu285ZqQEEVjOqM9W2OtdUwuL0xKX/AEpNVbLph2F jUNhQJvysXME2MhuiJJZvrIQNWjVdSGFmYjUK79i9rJEknGkvJYalS2zORzgwhlA/+oP iBvlskeCtb2WAUDodmV9/VmkIEeMGP0NYKo3t8W118E1JuhohTwr4pNr5c0p651QJsfj aTeg== 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=9wQ6fMezSdLZOH3yCwwP8txdKVsSqHmnbv4sE+lH8gs=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=L3T7dhjdBvojkdTF0Lc2U+qz19GvIdBm0K8cO2rZh3UepDmAYTGEtXKJN0DBtOiCAo fXbxm51d+eIWQ19ZkIwpmuDYjVOV0mu0Xqzf5lmhBfvtXqYNOdLoXr8wksT5Fb0Ysjid vAYFmXbubB3etKapMsRHYFh2gARI0st9reThY4YnEy0plGQkjX29R/k2bUiLOI19iSRr vFRr+nXFmzFro0G6yXmJqAl0lfpK49aYqR85mL/sH2KYcf6E4vbk6/GsMSbFyJgVrLkP nzL7WKFcCE/E+TNk38Uo9wQNtLrOyLifRvR0HAgzlDbzi2oY+FjZMDgzJa3xs0saHgBN 4imQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Ernh+3fo; 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 x24-20020a170906299800b00992e23ef220si5895190eje.567.2023.07.12.19.40.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 19:40:44 -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=Ernh+3fo; 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 06A14385DC0C for ; Thu, 13 Jul 2023 02:40:01 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 06A14385DC0C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689216001; bh=9wQ6fMezSdLZOH3yCwwP8txdKVsSqHmnbv4sE+lH8gs=; 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=Ernh+3fojsawW8fAPowwzRi0PjkGGz21Uke/KW7xuMsw21Cx+SupMkS82AIzdvI/d 0Sw6qpRj/2DPPtu7LuxP50THcv5i8t6eUjIujjntyVP0+BLIOPLoCykYh9pSnPF8wA 1VWHLi/KyaZSzrDbQt0SzdXBoTkfc8ikkZXbTTu8= 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 7B682385609B; Thu, 13 Jul 2023 02:39:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7B682385609B Received: from pps.filterd (m0247474.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36D2ReLQ006278; Thu, 13 Jul 2023 02:39:12 GMT Received: from mxout21.s.uw.edu (mxout21.s.uw.edu [140.142.32.139]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rt6eughj0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 02:39:11 +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 36D2d6TT005158 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 19:39:06 -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 36D2bY7F020817 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 19:39:06 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v10 2/5] libstdc++: Use new built-in trait __is_reference for std::is_reference Date: Wed, 12 Jul 2023 19:33:36 -0700 Message-ID: <20230713023731.15571-3-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713023731.15571-1-kmatsui@gcc.gnu.org> References: <20230708051137.63707-1-kmatsui@gcc.gnu.org> <20230713023731.15571-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: Aopk93Y4LlCxvGKit-2lJRXmgj0xrdJX X-Proofpoint-ORIG-GUID: Aopk93Y4LlCxvGKit-2lJRXmgj0xrdJX 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 impostorscore=0 mlxscore=0 lowpriorityscore=0 phishscore=0 spamscore=0 clxscore=1034 malwarescore=0 priorityscore=1501 adultscore=0 mlxlogscore=936 suspectscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307130021 X-Spam-Status: No, score=-13.0 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: 1771271402867130682 X-GMAIL-MSGID: 1771271402867130682 This patch gets std::is_reference to dispatch to new built-in trait __is_reference. libstdc++-v3/ChangeLog: * include/std/type_traits (is_reference): Use __is_reference built-in trait. (is_reference_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 0e7a9c9c7f3..2a14df7e5f9 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -639,6 +639,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // Composite type categories. /// is_reference +#if __has_builtin(__is_reference) + template + struct is_reference + : public __bool_constant<__is_reference(_Tp)> + { }; +#else template struct is_reference : public false_type @@ -653,6 +659,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION struct is_reference<_Tp&&> : public true_type { }; +#endif /// is_arithmetic template @@ -3192,12 +3199,19 @@ template inline constexpr bool is_class_v = __is_class(_Tp); template inline constexpr bool is_function_v = is_function<_Tp>::value; + +#if __has_builtin(__is_reference) +template + inline constexpr bool is_reference_v = __is_reference(_Tp); +#else template inline constexpr bool is_reference_v = false; template inline constexpr bool is_reference_v<_Tp&> = true; template inline constexpr bool is_reference_v<_Tp&&> = true; +#endif + template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template From patchwork Thu Jul 13 02:33:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119484 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1549068vqm; Wed, 12 Jul 2023 19:43:17 -0700 (PDT) X-Google-Smtp-Source: APBJJlHc1qZULBuBf/7FgcXLM4+V5Rkx7+Hm9AOKC8eVKxJjRu/uRjSMFOBnaasZ8jMGL3Z7xyvW X-Received: by 2002:a05:6402:3445:b0:51b:f669:9df3 with SMTP id l5-20020a056402344500b0051bf6699df3mr504926edc.4.1689216197169; Wed, 12 Jul 2023 19:43:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689216197; cv=none; d=google.com; s=arc-20160816; b=Td991TjtKWtiyEREQ1bJL3AOxoN/xCcJF7Ng7psngCDR/OTtxyX9Jsvh+bh8FbWmzu gAnodKX4xRRm0HJuYGD6EaCTVdm2r7kkJ18ok+1s09/TsUpJLyX5JT7RFJSvgIgr9/N4 dw5vJTD+pwZFMaVCzmO/l9DMgo49btLbQr4ceZOx2HTtiz8OmtAoBy7lYBxZrxTr9HI5 h0YbSY2FRCCuK8sRM/Q1SwyyjH6LebfNDItzAALatX2yYx/yMpliv801YnYtaLno2ITW kimZE1MRzLMG/03X9DHMe402iDjBGMuRLwHwhRvhAhlDsubNpsXU+fYhKjqmbhJOvvCQ 1+bg== 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=LtdZzR4eQFiU3m5LZaU/HL2s2t/f+um+shOoQAbg37Y=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=doM+U8pnHaH3zPT9Lo3FNMhLTafS/5cpJLmo6EJvuThTqKkPbSc7ftDZQ4pmptunAb zOlGm7nz4Pfny3U5meDSeVu56J6DQxtVOl13/qG/sV7UwO5PNXfF5yONc1Sn04JbZCtI t9F/I2SP7jgEWO2BRlZ7X2BtkuiGctlInpVmHmdFPrw+yq0XAAMMv9JHkOwUaA+kx667 zv/+xFOO+/3hs3YYIlxqUS9qkVIP/eAwC3DCOlkaa4o5++4v2RYjr5BHC51LLwrrXNrd bdmKAEYEU8mqTNwjhwOu2p1NbErWhUpUD/2BJt9tKKdPgsucT8em/fFgI9OnggdDzJHf JeDw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=RPErvSEf; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id g25-20020aa7d1d9000000b0051e16e83727si6209664edp.568.2023.07.12.19.43.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 19:43:17 -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=RPErvSEf; 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 B5AFF3854EB1 for ; Thu, 13 Jul 2023 02:41:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B5AFF3854EB1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689216086; bh=LtdZzR4eQFiU3m5LZaU/HL2s2t/f+um+shOoQAbg37Y=; 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=RPErvSEfmCGP6N+kZP2ltn4Ts63fRBhIF9+/78xjDgNyVdmLglL4gAml5EMkT9PaQ /XOVW4u0UNyXA4rMjzUmDSjW4D5XTTn0ReWnwINQL8fX7whbg7KqO2JQc5HPfxCo0W 2aSQv3h3DEHRITHAkdnRwFCoCAFdxEVFMtwjTfh4= 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 51E963854E9A; Thu, 13 Jul 2023 02:40:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 51E963854E9A Received: from pps.filterd (m0247470.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36D2b2rE016290; Thu, 13 Jul 2023 02:39:59 GMT Received: from mxout24.cac.washington.edu (mxout24.cac.washington.edu [140.142.234.158]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rt52gh390-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 02:39:59 +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 36D2dTOK012332 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 19:39:30 -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 36D2bY7G020817 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 19:39:29 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v10 3/5] c++: Implement __is_function built-in trait Date: Wed, 12 Jul 2023 19:33:37 -0700 Message-ID: <20230713023731.15571-4-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713023731.15571-1-kmatsui@gcc.gnu.org> References: <20230708051137.63707-1-kmatsui@gcc.gnu.org> <20230713023731.15571-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: S102X2_InAciI_7ljda56dqgVKazTInX X-Proofpoint-ORIG-GUID: S102X2_InAciI_7ljda56dqgVKazTInX 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 impostorscore=0 phishscore=0 priorityscore=1501 mlxlogscore=881 adultscore=0 clxscore=1034 bulkscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307130021 X-Spam-Status: No, score=-13.0 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: 1771271563517664152 X-GMAIL-MSGID: 1771271563517664152 This patch implements built-in trait for std::is_function. gcc/cp/ChangeLog: * cp-trait.def: Define __is_function. * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_FUNCTION. * semantics.cc (trait_expr_value): Likewise. (finish_trait_expr): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: Test existence of __is_function. * g++.dg/ext/is_function.C: New test. 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_function.C | 58 ++++++++++++++++++++++++ 5 files changed, 69 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/is_function.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index f6951ee2670..927605c6cb7 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -3754,6 +3754,9 @@ diagnose_trait_expr (tree expr, tree args) case CPTK_IS_UNION: inform (loc, " %qT is not a union", t1); break; + case CPTK_IS_FUNCTION: + inform (loc, " %qT is not a function", 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 1e3310cd682..3cd3babc242 100644 --- a/gcc/cp/cp-trait.def +++ b/gcc/cp/cp-trait.def @@ -83,6 +83,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_FUNCTION, "__is_function", 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 2f37bc353a1..b976633645a 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12072,6 +12072,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_ENUM: return type_code1 == ENUMERAL_TYPE; + case CPTK_IS_FUNCTION: + return type_code1 == FUNCTION_TYPE; + case CPTK_IS_FINAL: return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1); @@ -12293,6 +12296,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) case CPTK_IS_UNION: case CPTK_IS_SAME: case CPTK_IS_REFERENCE: + case CPTK_IS_FUNCTION: 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 b697673790c..90eb00ebf2d 100644 --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -149,3 +149,6 @@ #if !__has_builtin (__is_reference) # error "__has_builtin (__is_reference) failed" #endif +#if !__has_builtin (__is_function) +# error "__has_builtin (__is_function) failed" +#endif diff --git a/gcc/testsuite/g++.dg/ext/is_function.C b/gcc/testsuite/g++.dg/ext/is_function.C new file mode 100644 index 00000000000..2e1594b12ad --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_function.C @@ -0,0 +1,58 @@ +// { dg-do compile { target c++11 } } + +#include + +using namespace __gnu_test; + +#define SA(X) static_assert((X),#X) +#define SA_TEST_CATEGORY(TRAIT, TYPE, EXPECT) \ + SA(TRAIT(TYPE) == EXPECT); \ + SA(TRAIT(const TYPE) == EXPECT); \ + SA(TRAIT(volatile TYPE) == EXPECT); \ + SA(TRAIT(const volatile TYPE) == EXPECT) + +struct A +{ void fn(); }; + +template +struct AHolder { }; + +template +struct AHolder +{ using type = U; }; + +// Positive tests. +SA(__is_function(int (int))); +SA(__is_function(ClassType (ClassType))); +SA(__is_function(float (int, float, int[], int&))); +SA(__is_function(int (int, ...))); +SA(__is_function(bool (ClassType) const)); +SA(__is_function(AHolder::type)); + +void fn(); +SA(__is_function(decltype(fn))); + +// Negative tests. +SA_TEST_CATEGORY(__is_function, int, false); +SA_TEST_CATEGORY(__is_function, int*, false); +SA_TEST_CATEGORY(__is_function, int&, false); +SA_TEST_CATEGORY(__is_function, void, false); +SA_TEST_CATEGORY(__is_function, void*, false); +SA_TEST_CATEGORY(__is_function, void**, false); +SA_TEST_CATEGORY(__is_function, std::nullptr_t, false); + +SA_TEST_CATEGORY(__is_function, AbstractClass, false); +SA(!__is_function(int(&)(int))); +SA(!__is_function(int(*)(int))); + +SA_TEST_CATEGORY(__is_function, A, false); +SA_TEST_CATEGORY(__is_function, decltype(&A::fn), false); + +struct FnCallOverload +{ void operator()(); }; +SA_TEST_CATEGORY(__is_function, FnCallOverload, false); + +// Sanity check. +SA_TEST_CATEGORY(__is_function, ClassType, false); +SA_TEST_CATEGORY(__is_function, IncompleteClass, false); +SA_TEST_CATEGORY(__is_function, IncompleteUnion, false); From patchwork Thu Jul 13 02:33:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119485 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1549118vqm; Wed, 12 Jul 2023 19:43:25 -0700 (PDT) X-Google-Smtp-Source: APBJJlFh+J1de340CVE3pUOlvWSryPsG5FatKfIkdQogrHzigoD0MmBsFQlhhnEpXfdjIGlMBroQ X-Received: by 2002:a17:907:7e8d:b0:98e:4f1:f987 with SMTP id qb13-20020a1709077e8d00b0098e04f1f987mr4828572ejc.3.1689216205353; Wed, 12 Jul 2023 19:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689216205; cv=none; d=google.com; s=arc-20160816; b=qab3Ycrp7yPcvcDHA/irDsAoNokE11zncXzJt5gx2zAGDIs7dx1xCm1p44I5w+pqGT ZfMoY9m87M4lWP3qKKpN2UyuCxdQCzW+iDR3VuQ635/EHeAblZElvzOWsRCv7ha5xswA IHWZU2YsWaDWV6JwAPskC5DNrU9ET7nXgbaMGa0fILLAw3IeBSUd1hdCiGBc9YucumGI eMevSpiduUB5XbpzoaLsQZSjn985N4oiOTtDG+FO+2PepGOFGB+u776oIsjXnE8SxliZ //vPB5OoOOBKqoy9d5f6VMSpLElZ+yvqajPKOFqBe5KSWcWHG83yLF1/wukUnBYnD38X szig== 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=KVQ0wo9zPz94gs1P+vCySNJyvizFXIim3dbIWWJp8rQ=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=opKd/xlWYBPM2U2fyEc+inV9D2WQcidtbaliFs7e0uRUNgj2JUq0SmqWbRZynsISp6 FtblpipC23QKGGlInfxWPJgMF4LLhpiWWULXcOSAVB4BR3egew7WZjM4OWJNMCOOFudj 8q7SZJDZKuALPCztwPVAX+3scc2EKkGnk4YIiQyU3gKEumsCBkHc/0oF9xDcpi4N6Ky7 fS7cyoRVVLrqz7cOObj1FfhyGT+UZNf3WXrd6t8U9nm5tajaSlJ41j/WVjFTTKBhiBgJ VxbxXRvrPvp2d5PzgbBXub0QckHcVimB09nec97n1NBCJj/wp2JMiMkYB8dhQa/iHu0P 5XOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=WdnV0494; 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 (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id u18-20020aa7d892000000b0051e5cabfebdsi6161815edq.373.2023.07.12.19.43.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 19:43:25 -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=WdnV0494; 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 B3B78385E451 for ; Thu, 13 Jul 2023 02:41:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3B78385E451 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689216093; bh=KVQ0wo9zPz94gs1P+vCySNJyvizFXIim3dbIWWJp8rQ=; 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=WdnV0494vF46ZbnxHLz+ohpcmljB8FgUZryhKTessdyGcj1eSvgFv775vR0fXqePE zrkN0MKQMVPTD4dS3YRzEtW7PFeN7FostRwHsZxX+TQfpX2sC0Aamftm6nDabyCxrh MSaL1LF61dbT0U912xc6kxEUg1i9KZnJSmIvu7oA= 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 31F1E3857C66; Thu, 13 Jul 2023 02:40:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 31F1E3857C66 Received: from pps.filterd (m0247477.ppops.net [127.0.0.1]) by mx0a-00641c01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36D2UbS4028963; Thu, 13 Jul 2023 02:40:44 GMT Received: from mxout25.s.uw.edu (mxout25.s.uw.edu [140.142.234.175]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rt25eam7s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 02:40:44 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout25.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36D2eF93014177 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 19:40:16 -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 36D2bY7H020817 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 19:40:15 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v10 4/5] libstdc++: Use new built-in trait __is_function for std::is_function Date: Wed, 12 Jul 2023 19:33:38 -0700 Message-ID: <20230713023731.15571-5-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713023731.15571-1-kmatsui@gcc.gnu.org> References: <20230708051137.63707-1-kmatsui@gcc.gnu.org> <20230713023731.15571-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 46geHwlJ8gGbddtDY21159i5jsMNuyY7 X-Proofpoint-GUID: 46geHwlJ8gGbddtDY21159i5jsMNuyY7 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 suspectscore=0 malwarescore=0 mlxlogscore=730 clxscore=1034 phishscore=0 lowpriorityscore=0 priorityscore=1501 impostorscore=0 spamscore=0 bulkscore=0 adultscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307130021 X-Spam-Status: No, score=-13.0 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: 1771271572052372578 X-GMAIL-MSGID: 1771271572052372578 This patch gets std::is_function to dispatch to new built-in trait __is_function. libstdc++-v3/ChangeLog: * include/std/type_traits (is_function): Use __is_function built-in trait. (is_function_v): Likewise. Optimize its implementation. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 2a14df7e5f9..7ef50a2e64f 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -594,6 +594,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_function +#if __has_builtin(__is_function) + template + struct is_function + : public __bool_constant<__is_function(_Tp)> + { }; +#else template struct is_function : public __bool_constant::value> { }; @@ -605,6 +611,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template struct is_function<_Tp&&> : public false_type { }; +#endif #define __cpp_lib_is_null_pointer 201309L @@ -3197,8 +3204,18 @@ template inline constexpr bool is_union_v = __is_union(_Tp); template inline constexpr bool is_class_v = __is_class(_Tp); + +#if __has_builtin(__is_function) template - inline constexpr bool is_function_v = is_function<_Tp>::value; + inline constexpr bool is_function_v = __is_function(_Tp); +#else +template + inline constexpr bool is_function_v = !is_const_v; +template + inline constexpr bool is_function_v<_Tp&> = false; +template + inline constexpr bool is_function_v<_Tp&&> = false; +#endif #if __has_builtin(__is_reference) template From patchwork Thu Jul 13 02:33:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ken Matsui X-Patchwork-Id: 119486 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a6b2:0:b0:3e4:2afc:c1 with SMTP id c18csp1549763vqm; Wed, 12 Jul 2023 19:45:31 -0700 (PDT) X-Google-Smtp-Source: APBJJlFU0E1g3xRV3EoU65xq8zodDrSTmx8hqZLUiBm8tY9mvl9qzKqLbCBV9cmOdF7CyXGKRcn4 X-Received: by 2002:a17:906:341b:b0:992:a836:a194 with SMTP id c27-20020a170906341b00b00992a836a194mr102919ejb.59.1689216331726; Wed, 12 Jul 2023 19:45:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689216331; cv=none; d=google.com; s=arc-20160816; b=r457x6+ewxpL2FMPEkf9JrVATqZVtOAJa5kXXr6B6iF4KIvIl7YDxC90UKPOG2OySq aermqm5jYnOsqJ/mDtou6Rs7mCxOA0KH9N35/iESN9vBdWxb5aX+IRrfJQb2P7DvRX3F Edr/L0IhxNnTKaewKrLZ7IRx1mKY/Ce7+c+4gemPNzKQqzlq5h7VEFicRY9lbO6GbPYg 1fWN0qSp4M5LNtCJm3SbiB2aM8mKKrA31Ryd8nz0tvdxUQis+iUjQ0LgSMK1dGhm8AoM PR90w2jnruG61DUuTcDiTnCHFyJyRpQmetOpdEYl4UxMRSSSZmW9IVBMSHKqZVylXS7I U51w== 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=slFWQaRBCu49MmVlNxMi1dmmU2SllkckIGyWaVURhRU=; fh=1CAabwJrK+ugngH18pg8mqZVlwzSJe6ffxxXK5OO7Vs=; b=ezOiPJpLqyDTQazf99etQv0tDZUUAzzvnGL5LG1/UUaiewzH3n8gLKdA3Ep9F1fx/V 7AkorpFO4fiTunEgcmUtau2hk7KrgT3M5CXZXfKedXeF3+SREaZJXalesC0Z4/PFJPmp L1MjA7iH/2nzcIYaGVIa+qQbLYzk2fbU8FOnlnJ42nyEEoNO/KSosElVrUD5sjsG6Ty5 p/fildNAU5PqQLzLzYZOB9feRbpGveRhznChj4FthDvMxCSRYYqIbPZn0Er881XUsFH1 dZ1LFTYEARnndIkRVmjueYBbHJo9yKN0sxWNIjSfcLr63iuhEnYJyK4islYIgs6dOuu9 XS+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=XIi1yR7r; 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 f10-20020a170906390a00b00992a096678fsi6017910eje.813.2023.07.12.19.45.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jul 2023 19:45:31 -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=XIi1yR7r; 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 B673B3857736 for ; Thu, 13 Jul 2023 02:43:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B673B3857736 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689216217; bh=slFWQaRBCu49MmVlNxMi1dmmU2SllkckIGyWaVURhRU=; 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=XIi1yR7rpWPbv14/PU6jLMLr9Y5oJYaxGbZYG6+QP+3TcHCa0LcXZicLHT9QhrZ1p j39mkhFp9xQ7RZZaRtzh3JvGxykL5juBCIOsiwY23iBMT5fOH1N0/XTM4/sn1HKh+m gQy1VmMrkO9BkPMp6uAgu1tYIxYbD2rnP3765Ptg= 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 388713854E90; Thu, 13 Jul 2023 02:42:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 388713854E90 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 36D2Yuun008448; Thu, 13 Jul 2023 02:42:07 GMT Received: from mxout26.s.uw.edu (mxout26.s.uw.edu [140.142.234.176]) by mx0a-00641c01.pphosted.com (PPS) with ESMTPS id 3rsy34vhx9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 13 Jul 2023 02:42:06 +0000 Received: from smtp.washington.edu (smtp.washington.edu [128.208.60.54]) by mxout26.s.uw.edu (8.14.4+UW20.07/8.14.4+UW22.04) with ESMTP id 36D2fcQc019232 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 12 Jul 2023 19:41:38 -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 36D2bY7I020817 (version=TLSv1.2 cipher=DHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT); Wed, 12 Jul 2023 19:41:38 -0700 X-UW-Orig-Sender: kmatsui@smtp.washington.edu To: gcc-patches@gcc.gnu.org Cc: libstdc++@gcc.gnu.org, Ken Matsui Subject: [PATCH v10 5/5] libstdc++: Make std::is_object dispatch to new built-in traits Date: Wed, 12 Jul 2023 19:33:39 -0700 Message-ID: <20230713023731.15571-6-kmatsui@gcc.gnu.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230713023731.15571-1-kmatsui@gcc.gnu.org> References: <20230708051137.63707-1-kmatsui@gcc.gnu.org> <20230713023731.15571-1-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Proofpoint-GUID: keyKzlPS5iNiH6urO12vSeT1I9wpGgjR X-Proofpoint-ORIG-GUID: keyKzlPS5iNiH6urO12vSeT1I9wpGgjR 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=988 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-2307130022 X-Spam-Status: No, score=-13.0 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: 1771271703942091686 X-GMAIL-MSGID: 1771271703942091686 This patch gets std::is_object to dispatch to new built-in traits, __is_function and __is_reference. libstdc++-v3/ChangeLog: * include/std/type_traits (is_object): Use new built-in traits, __is_function and __is_reference. (is_object_v): Likewise. Signed-off-by: Ken Matsui --- libstdc++-v3/include/std/type_traits | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 7ef50a2e64f..4ff025b09fa 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -682,11 +682,20 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { }; /// is_object +#if __has_builtin(__is_function) && __has_builtin(__is_reference) \ + && __has_builtin(__is_void) + template + struct is_object + : public __bool_constant + { }; +#else template struct is_object : public __not_<__or_, is_reference<_Tp>, is_void<_Tp>>>::type { }; +#endif template struct is_member_pointer; @@ -3233,8 +3242,16 @@ template inline constexpr bool is_arithmetic_v = is_arithmetic<_Tp>::value; template inline constexpr bool is_fundamental_v = is_fundamental<_Tp>::value; + +#if __has_builtin(__is_function) && __has_builtin(__is_reference) +template + inline constexpr bool is_object_v + = !(__is_function(_Tp) || __is_reference(_Tp) || is_void<_Tp>::value); +#else template inline constexpr bool is_object_v = is_object<_Tp>::value; +#endif + template inline constexpr bool is_scalar_v = is_scalar<_Tp>::value; template