From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id F0819385840D for ; Mon, 16 Oct 2023 17:16:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F0819385840D Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org F0819385840D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697476569; cv=none; b=hc89WZknVWOUGTd2GLnqbzalYeRPciRLaS8yho1y1KG8vhtD99VeOgA4bIdA2zPASB3N3xpRANEPVqGtQfkoWARWS5aizppsRxdkm6n1HhskibC/8klWrUwralrkjrX8RlkOuJmfJJ17VXSR1X/p3X7G6p7YH5XPfrvEaZEElVk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1697476569; c=relaxed/simple; bh=HBtZ8sX+22t+k7sxLTTlo8IHJF2hIplg3BdWe02SCgk=; h=DKIM-Signature:From:Date:To:Subject:Message-ID:MIME-Version; b=ChbfLYlgARq+CEAieKcOoY4epdGhTROzZPzFBMs4qGS3fIdXsUsvGyZnEafAzmPplXZfKsjrc7f74B/hzyUJfIWQOq5TbWVzobNFr2CcfzFBosG4PigedvbSUDIqK2UuSzt3PdxJ0Aft9yYphHINOWbPgr7hyOw6ShBc8iZ0vSI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1697476565; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=/WiaWLbRcJqMPD9WV96IN3pDEqqfQhWyjuMXjQHFUZU=; b=KmWmdeqJELV/09eLVI62NwFwKkzTyxVdkTMSIOvZ9VBNNj/DWI2Zc8JPYkxIMPGm9/3Y6u dOcJbKDAMsU3F8eUI44zGjc8hQCMahx2duu09eWtRHTZio1TOlC+/fcrkjZNcEeaCZ5iS2 NAWP394Yi1s06bJtcShgvlxE9EbDf+g= Received: from mail-oi1-f198.google.com (mail-oi1-f198.google.com [209.85.167.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-482-OUhQVIKoPOiHX8GHYQXlzQ-1; Mon, 16 Oct 2023 13:16:04 -0400 X-MC-Unique: OUhQVIKoPOiHX8GHYQXlzQ-1 Received: by mail-oi1-f198.google.com with SMTP id 5614622812f47-3af5aa51bacso6582821b6e.3 for ; Mon, 16 Oct 2023 10:16:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697476563; x=1698081363; h=mime-version:references:message-id:in-reply-to:subject:cc:to:date :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=/WiaWLbRcJqMPD9WV96IN3pDEqqfQhWyjuMXjQHFUZU=; b=VNfrO8YDSZ+U+SKQ/uda4fsIJnSCFBNYvfeBeI96lxcARKAGZZGlYAc96Lsj/XFxwD zRGEg1mcIYCIkXMSSi6W8i5QJlluQCZizEiO/blxbBSgF5KdQyKDRtc6mEkhhKJ3qCM5 ATmkujTJYlNv81bozQUUTIdzypE3CrmK8bWruRf2MIWebTo/JcboD8yQwTiOy31Ixhit PyIfDp1z1e/3TDCwiarwfoXYE7Qd1n0JkgjN9cQ6BHaPJvxVmjwwwuDEmpgInZRdC+fp IV7/kWEPknblqzbX+BLAbXZN+n3atmjAgcOY8yROQ4ic6YUureg4QQIdLZkYy7ZEP/r4 wYhg== X-Gm-Message-State: AOJu0YwvMp2SpKMXkWK3txmvEUxazCF+1KErmJKk5jDH3dkg/UNq36Eq ebqnYISIwVp4UoDWTVcu74ByW4CsYXVFiQgkU5BiqzlY9Fakg/BMvNnCSFrWe8pd1Fqo7stYfHz AsSKRPhIoDEaejOc= X-Received: by 2002:aca:2808:0:b0:3a3:9df9:1918 with SMTP id 8-20020aca2808000000b003a39df91918mr29618517oix.20.1697476563625; Mon, 16 Oct 2023 10:16:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFgtp2khuNl/KJ1qoelqa2adX9IFIjj7A/v0QAp5wDuzavaDYD6QH5fCld1gDd6X1g+iWPC7A== X-Received: by 2002:aca:2808:0:b0:3a3:9df9:1918 with SMTP id 8-20020aca2808000000b003a39df91918mr29618509oix.20.1697476563319; Mon, 16 Oct 2023 10:16:03 -0700 (PDT) Received: from [192.168.1.130] (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id y10-20020a0ce80a000000b0065b08bb01afsm3579395qvn.124.2023.10.16.10.16.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 10:16:02 -0700 (PDT) From: Patrick Palka X-Google-Original-From: Patrick Palka Date: Mon, 16 Oct 2023 13:16:02 -0400 (EDT) To: Ken Matsui cc: gcc-patches@gcc.gnu.org, libstdc++@gcc.gnu.org Subject: Re: [PATCH v20 31/40] c++: Implement __is_arithmetic built-in trait In-Reply-To: <20231016001227.2717180-32-kmatsui@gcc.gnu.org> Message-ID: References: <20231013223957.1634024-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-1-kmatsui@gcc.gnu.org> <20231016001227.2717180-32-kmatsui@gcc.gnu.org> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-13.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Sun, 15 Oct 2023, Ken Matsui wrote: > This patch implements built-in trait for std::is_arithmetic. > > gcc/cp/ChangeLog: > > * cp-trait.def: Define __is_arithmetic. > * constraint.cc (diagnose_trait_expr): Handle CPTK_IS_ARITHMETIC. > * semantics.cc (trait_expr_value): Likewise. > (finish_trait_expr): Likewise. > > gcc/testsuite/ChangeLog: > > * g++.dg/ext/has-builtin-1.C: Test existence of __is_arithmetic. > * g++.dg/ext/is_arithmetic.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_arithmetic.C | 33 ++++++++++++++++++++++++ > 5 files changed, 44 insertions(+) > create mode 100644 gcc/testsuite/g++.dg/ext/is_arithmetic.C > > diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc > index c9d627fa782..3a7f968eae8 100644 > --- a/gcc/cp/constraint.cc > +++ b/gcc/cp/constraint.cc > @@ -3714,6 +3714,9 @@ diagnose_trait_expr (tree expr, tree args) > case CPTK_IS_AGGREGATE: > inform (loc, " %qT is not an aggregate", t1); > break; > + case CPTK_IS_ARITHMETIC: > + inform (loc, " %qT is not an arithmetic type", t1); > + break; > case CPTK_IS_ARRAY: > inform (loc, " %qT is not an array", t1); > break; > diff --git a/gcc/cp/cp-trait.def b/gcc/cp/cp-trait.def > index c60724e869e..b2be7b7bbd7 100644 > --- a/gcc/cp/cp-trait.def > +++ b/gcc/cp/cp-trait.def > @@ -59,6 +59,7 @@ DEFTRAIT_EXPR (HAS_UNIQUE_OBJ_REPRESENTATIONS, "__has_unique_object_representati > DEFTRAIT_EXPR (HAS_VIRTUAL_DESTRUCTOR, "__has_virtual_destructor", 1) > DEFTRAIT_EXPR (IS_ABSTRACT, "__is_abstract", 1) > DEFTRAIT_EXPR (IS_AGGREGATE, "__is_aggregate", 1) > +DEFTRAIT_EXPR (IS_ARITHMETIC, "__is_arithmetic", 1) > DEFTRAIT_EXPR (IS_ARRAY, "__is_array", 1) > DEFTRAIT_EXPR (IS_ASSIGNABLE, "__is_assignable", 2) > DEFTRAIT_EXPR (IS_BASE_OF, "__is_base_of", 2) > diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc > index 83ed674b9d4..deab0134509 100644 > --- a/gcc/cp/semantics.cc > +++ b/gcc/cp/semantics.cc > @@ -12143,6 +12143,9 @@ trait_expr_value (cp_trait_kind kind, tree type1, tree type2) > case CPTK_IS_AGGREGATE: > return CP_AGGREGATE_TYPE_P (type1); > > + case CPTK_IS_ARITHMETIC: > + return ARITHMETIC_TYPE_P (type1); > + For built-ins corresponding to is_arithmetic and other standard traits defined in terms of it (e.g. is_scalar, is_unsigned, is_signed, is_fundamental) we need to make sure we preserve their behavior for __int128, which IIUC is currently recognized as an integral type (according to std::is_integral) only in GNU mode. This'll probably be subtle to get right, so if you don't mind let's split out the work for those built-in traits into a separate patch series in order to ease review of the main patch series. > case CPTK_IS_ARRAY: > return type_code1 == ARRAY_TYPE; > > @@ -12406,6 +12409,7 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) > return error_mark_node; > break; > > + case CPTK_IS_ARITHMETIC: > case CPTK_IS_ARRAY: > case CPTK_IS_BOUNDED_ARRAY: > case CPTK_IS_CLASS: > diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C > index efce04fd09d..4bc85f4babb 100644 > --- a/gcc/testsuite/g++.dg/ext/has-builtin-1.C > +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C > @@ -56,6 +56,9 @@ > #if !__has_builtin (__is_aggregate) > # error "__has_builtin (__is_aggregate) failed" > #endif > +#if !__has_builtin (__is_arithmetic) > +# error "__has_builtin (__is_arithmetic) failed" > +#endif > #if !__has_builtin (__is_array) > # error "__has_builtin (__is_array) failed" > #endif > diff --git a/gcc/testsuite/g++.dg/ext/is_arithmetic.C b/gcc/testsuite/g++.dg/ext/is_arithmetic.C > new file mode 100644 > index 00000000000..fd35831f646 > --- /dev/null > +++ b/gcc/testsuite/g++.dg/ext/is_arithmetic.C > @@ -0,0 +1,33 @@ > +// { 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) > + > +SA_TEST_CATEGORY(__is_arithmetic, void, false); > + > +SA_TEST_CATEGORY(__is_arithmetic, char, true); > +SA_TEST_CATEGORY(__is_arithmetic, signed char, true); > +SA_TEST_CATEGORY(__is_arithmetic, unsigned char, true); > +SA_TEST_CATEGORY(__is_arithmetic, wchar_t, true); > +SA_TEST_CATEGORY(__is_arithmetic, short, true); > +SA_TEST_CATEGORY(__is_arithmetic, unsigned short, true); > +SA_TEST_CATEGORY(__is_arithmetic, int, true); > +SA_TEST_CATEGORY(__is_arithmetic, unsigned int, true); > +SA_TEST_CATEGORY(__is_arithmetic, long, true); > +SA_TEST_CATEGORY(__is_arithmetic, unsigned long, true); > +SA_TEST_CATEGORY(__is_arithmetic, long long, true); > +SA_TEST_CATEGORY(__is_arithmetic, unsigned long long, true); > +SA_TEST_CATEGORY(__is_arithmetic, float, true); > +SA_TEST_CATEGORY(__is_arithmetic, double, true); > +SA_TEST_CATEGORY(__is_arithmetic, long double, true); > + > +// Sanity check. > +SA_TEST_CATEGORY(__is_arithmetic, ClassType, false); > -- > 2.42.0 > >