From patchwork Mon Aug 29 21:26:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 822 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:ecc5:0:0:0:0:0 with SMTP id s5csp1592789wro; Mon, 29 Aug 2022 14:27:06 -0700 (PDT) X-Google-Smtp-Source: AA6agR53yYVmpOHmpROmXEJ6B5D98uSLaD5yfwfKyEfuVg4MYdPV+9CTtSlvl/WARRCcjk53q1o2 X-Received: by 2002:a17:906:9bf0:b0:741:362a:3ff1 with SMTP id de48-20020a1709069bf000b00741362a3ff1mr10330595ejc.275.1661808426672; Mon, 29 Aug 2022 14:27:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661808426; cv=none; d=google.com; s=arc-20160816; b=pD9tTZ0S8E3xu6CFNEPK7QUsjvgl5OT2jwSyiKTHoxq3Redmil9Rt6d0cKkFsvzL+B l9zPe6lZnmv51y/rIlmb/J6BrCanyZSlWrcYcxYty0hpBYyZyuQpfgfGPD79KEmpMJds PDEPU0q/RU2c6T3x7PBp++Qb1kgEgh8tIqePK3+aA6JQ7tBESnuzC0bcudPelKQkwHQF lgQGTkUOGxyeeKmh+NTtY29cT7UysOJx6dHkbbBLtLwD3s9w949nBj+aDC0rbmaBG6Ot Sxqooh0MvDL7b6ityRjWg2ZojfUtuKIsRT5Ox4DQH9HjLdXrG8+iDRsLkkiu5+zyz9jF 0f7g== 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:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=A9b20wGk92t7s0UHpqs/B1mRPw1p3N4kmb4W/BJ+DtM=; b=VOmvvR0YrKGSk/dgeE5voax4ghBRRvQskys9up7Kx4ThY8KFoOyxYCVrw+okGZwcRt vkDWtYehOULpMvMWLFu1sJRdib5zFrkbpH3JUxzZGenhz9vj4an5CfKjpthz3zAhty+I Zbjky24KN7KTSHwQ+uCzWJuCFlq0ukyPUBAQcXVlHKcvxxuoo32SPdBPHpTKhpw5JCsh Sw8oN1D9CUt36hyOGUs4JI1iKNsUZ48w5V0hJl1dgW82pJSzmtGagfeQiEED2HbXYnrR b9p5lxm2bAczGNGOUr8LeFA2t77hOOTD+6MSmf1IOVrNHoDHz7wY1moZqWDZeVATSS6g 2lCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=LSfp7AL4; 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 sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hs8-20020a1709073e8800b00730a4246dd0si4218945ejc.593.2022.08.29.14.27.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Aug 2022 14:27:06 -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=LSfp7AL4; 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 9DB973856962 for ; Mon, 29 Aug 2022 21:26:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9DB973856962 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661808418; bh=A9b20wGk92t7s0UHpqs/B1mRPw1p3N4kmb4W/BJ+DtM=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=LSfp7AL4J5ip/W2lW2ldnP+FuXHxoT7FHQD4hdLVFfXWhvrucH7QIPx/y6psSlsnq wET7ZUL1YD7cUyBx2XGjvbGYkUHWkSuGi1j7/Ei3veSUHepfYg5G/5f2/epoGujpoT AwR7lTl4Fq7UvjpC8ovbMjBTB9jKJviP4nZjNhJw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org 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 D6E983856959 for ; Mon, 29 Aug 2022 21:26:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D6E983856959 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-172-VLng_FN2N-KmrBVDV-XSoQ-1; Mon, 29 Aug 2022 17:26:09 -0400 X-MC-Unique: VLng_FN2N-KmrBVDV-XSoQ-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 9E015811E87 for ; Mon, 29 Aug 2022 21:26:08 +0000 (UTC) Received: from pdp-11.redhat.com (unknown [10.22.17.143]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7B5C02026D4C; Mon, 29 Aug 2022 21:26:08 +0000 (UTC) To: Jason Merrill , GCC Patches Subject: [PATCH] c++: __has_builtin gives the wrong answer [PR106759] Date: Mon, 29 Aug 2022 17:26:03 -0400 Message-Id: <20220829212603.632168-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.2 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, SPF_HELO_NONE, SPF_NONE, 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek 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?1742532432899392649?= X-GMAIL-MSGID: =?utf-8?q?1742532432899392649?= We've supported __is_nothrow_constructible since r11-4386, but names_builtin_p didn't know about it, so it gave the wrong answer for #if __has_builtin(__is_nothrow_constructible) ... #endif I've tested all C++-only built-ins and only two were missing. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR c++/106759 gcc/cp/ChangeLog: * cp-objcp-common.cc (names_builtin_p): Handle RID_IS_NOTHROW_ASSIGNABLE and RID_IS_NOTHROW_CONSTRUCTIBLE. gcc/testsuite/ChangeLog: * g++.dg/ext/has-builtin-1.C: New test. --- gcc/cp/cp-objcp-common.cc | 2 + gcc/testsuite/g++.dg/ext/has-builtin-1.C | 133 +++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/has-builtin-1.C base-commit: b504149d2c92ddfcfab62ea6d1ed49ae72493e38 diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc index 4079a4b4aec..1ffac08c32f 100644 --- a/gcc/cp/cp-objcp-common.cc +++ b/gcc/cp/cp-objcp-common.cc @@ -460,6 +460,8 @@ names_builtin_p (const char *name) case RID_IS_UNION: case RID_IS_ASSIGNABLE: case RID_IS_CONSTRUCTIBLE: + case RID_IS_NOTHROW_ASSIGNABLE: + case RID_IS_NOTHROW_CONSTRUCTIBLE: case RID_UNDERLYING_TYPE: case RID_REF_CONSTRUCTS_FROM_TEMPORARY: case RID_REF_CONVERTS_FROM_TEMPORARY: diff --git a/gcc/testsuite/g++.dg/ext/has-builtin-1.C b/gcc/testsuite/g++.dg/ext/has-builtin-1.C new file mode 100644 index 00000000000..fe25cb2f669 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/has-builtin-1.C @@ -0,0 +1,133 @@ +// PR c++/106759 +// { dg-do compile } +// Verify that __has_builtin gives the correct answer for C++ built-ins. + +#if !__has_builtin (__builtin_addressof) +# error "__has_builtin (__builtin_addressof) failed" +#endif +#if !__has_builtin (__builtin_bit_cast) +# error "__has_builtin (__builtin_bit_cast) failed" +#endif +#if !__has_builtin (__builtin_launder) +# error "__has_builtin (__builtin_launder) failed" +#endif +#if !__has_builtin (__has_nothrow_assign) +# error "__has_builtin (__has_nothrow_assign) failed" +#endif +#if !__has_builtin (__has_nothrow_constructor) +# error "__has_builtin (__has_nothrow_constructor) failed" +#endif +#if !__has_builtin (__has_nothrow_copy) +# error "__has_builtin (__has_nothrow_copy) failed" +#endif +#if !__has_builtin (__has_trivial_assign) +# error "__has_builtin (__has_trivial_assign) failed" +#endif +#if !__has_builtin (__has_trivial_constructor) +# error "__has_builtin (__has_trivial_constructor) failed" +#endif +#if !__has_builtin (__has_trivial_copy) +# error "__has_builtin (__has_trivial_copy) failed" +#endif +#if !__has_builtin (__has_trivial_destructor) +# error "__has_builtin (__has_trivial_destructor) failed" +#endif +#if !__has_builtin (__has_unique_object_representations) +# error "__has_builtin (__has_unique_object_representations) failed" +#endif +#if !__has_builtin (__has_virtual_destructor) +# error "__has_builtin (__has_virtual_destructor) failed" +#endif +#if !__has_builtin (__is_abstract) +# error "__has_builtin (__is_abstract) failed" +#endif +#if !__has_builtin (__is_aggregate) +# error "__has_builtin (__is_aggregate) failed" +#endif +#if !__has_builtin (__is_base_of) +# error "__has_builtin (__is_base_of) failed" +#endif +#if !__has_builtin (__is_class) +# error "__has_builtin (__is_class) failed" +#endif +#if !__has_builtin (__is_empty) +# error "__has_builtin (__is_empty) failed" +#endif +#if !__has_builtin (__is_enum) +# error "__has_builtin (__is_enum) failed" +#endif +#if !__has_builtin (__is_final) +# error "__has_builtin (__is_final) failed" +#endif +#if !__has_builtin (__is_layout_compatible) +# error "__has_builtin (__is_layout_compatible) failed" +#endif +#if !__has_builtin (__is_literal_type) +# error "__has_builtin (__is_literal_type) failed" +#endif +#if !__has_builtin (__is_pointer_interconvertible_base_of) +# error "__has_builtin (__is_pointer_interconvertible_base_of) failed" +#endif +#if !__has_builtin (__is_pod) +# error "__has_builtin (__is_pod) failed" +#endif +#if !__has_builtin (__is_polymorphic) +# error "__has_builtin (__is_polymorphic) failed" +#endif +#if !__has_builtin (__is_same) +# error "__has_builtin (__is_same) failed" +#endif +#if !__has_builtin (__is_same_as) +# error "__has_builtin (__is_same_as) failed" +#endif +#if !__has_builtin (__is_standard_layout) +# error "__has_builtin (__is_standard_layout) failed" +#endif +#if !__has_builtin (__is_trivial) +# error "__has_builtin (__is_trivial) failed" +#endif +#if !__has_builtin (__is_trivially_assignable) +# error "__has_builtin (__is_trivially_assignable) failed" +#endif +#if !__has_builtin (__is_trivially_constructible) +# error "__has_builtin (__is_trivially_constructible) failed" +#endif +#if !__has_builtin (__is_trivially_copyable) +# error "__has_builtin (__is_trivially_copyable) failed" +#endif +#if !__has_builtin (__is_union) +# error "__has_builtin (__is_union) failed" +#endif +#if !__has_builtin (__underlying_type) +# error "__has_builtin (__underlying_type) failed" +#endif +#if !__has_builtin (__is_assignable) +# error "__has_builtin (__is_assignable) failed" +#endif +#if !__has_builtin (__is_constructible) +# error "__has_builtin (__is_constructible) failed" +#endif +#if !__has_builtin (__is_nothrow_assignable) +# error "__has_builtin (__is_nothrow_assignable) failed" +#endif +#if !__has_builtin (__is_nothrow_constructible) +# error "__has_builtin (__is_nothrow_constructible) failed" +#endif +#if !__has_builtin (__reference_constructs_from_temporary) +# error "__has_builtin (__reference_constructs_from_temporary) failed" +#endif +#if !__has_builtin (__reference_converts_from_temporary) +# error "__has_builtin (__reference_converts_from_temporary) failed" +#endif +#if !__has_builtin (__builtin_is_constant_evaluated) +# error "__has_builtin (__builtin_is_constant_evaluated) failed" +#endif +#if !__has_builtin (__builtin_source_location) +# error "__has_builtin (__builtin_source_location) failed" +#endif +#if !__has_builtin (__builtin_is_corresponding_member) +# error "__has_builtin (__builtin_is_corresponding_member) failed" +#endif +#if !__has_builtin (__builtin_is_pointer_interconvertible_with_class) +# error "__has_builtin (__builtin_is_pointer_interconvertible_with_class) failed" +#endif