From patchwork Tue Sep 14 08:48:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 44982 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C9A463857C50 for ; Tue, 14 Sep 2021 08:48:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C9A463857C50 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1631609336; bh=2l8gS7zi0UZbET1RS6nkO7h/eBj2Gg2htWWGPG8Tboc=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=qjijjfTJK0wr1k32/oOox57FmApZgVkqDdiewMr2/99IlXeNnovACZZQks+gMKp11 DFPxUMRONkfH4O+H9SY6ElEALD206BPzM87O4aBE/v6lBQE6A3li0eFiXVp+p32re6 zRcsKHyUrOFrTRR8PqeCtK77yDQSOvrh4sTpfA7g= 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 ESMTP id B78993857C4F for ; Tue, 14 Sep 2021 08:48:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B78993857C4F Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-218-bojdrNHbM7q3MAtQMXG7vw-1; Tue, 14 Sep 2021 04:48:12 -0400 X-MC-Unique: bojdrNHbM7q3MAtQMXG7vw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 8878C19057A0 for ; Tue, 14 Sep 2021 08:48:11 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.10]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 221E61972D; Tue, 14 Sep 2021 08:48:10 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 18E8m9kQ1720866 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 14 Sep 2021 10:48:09 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 18E8m8nt1720865; Tue, 14 Sep 2021 10:48:08 +0200 Date: Tue, 14 Sep 2021 10:48:08 +0200 To: Jason Merrill Subject: [PATCH] c++: Fix __is_*constructible/assignable for templates [PR102305] Message-ID: <20210914084808.GU304296@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! is_xible_helper returns error_mark_node (i.e. false from the traits) for abstract classes by testing ABSTRACT_CLASS_TYPE_P (to) early. Unfortunately, as the testcase shows, that doesn't work on class templates that haven't been instantiated yet, ABSTRACT_CLASS_TYPE_P for them is false until it is instantiated, which is done when the routine later constructs a dummy object with that type. The following patch fixes this by calling complete_type first, so that ABSTRACT_CLASS_TYPE_P test will work properly, while keeping the handling of arrays with unknown bounds, or incomplete types where it is done currently. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2021-09-14 Jakub Jelinek PR c++/102305 * method.c (is_xible_helper): Call complete_type on to. * g++.dg/cpp0x/pr102305.C: New test. Jakub --- gcc/cp/method.c.jj 2021-08-12 09:34:16.465241411 +0200 +++ gcc/cp/method.c 2021-09-13 12:29:05.398000237 +0200 @@ -2081,6 +2081,7 @@ constructible_expr (tree to, tree from) static tree is_xible_helper (enum tree_code code, tree to, tree from, bool trivial) { + to = complete_type (to); deferring_access_check_sentinel acs (dk_no_deferred); if (VOID_TYPE_P (to) || ABSTRACT_CLASS_TYPE_P (to) || (from && FUNC_OR_METHOD_TYPE_P (from) --- gcc/testsuite/g++.dg/cpp0x/pr102305.C.jj 2021-09-13 12:46:47.580332966 +0200 +++ gcc/testsuite/g++.dg/cpp0x/pr102305.C 2021-09-13 12:49:00.072503394 +0200 @@ -0,0 +1,39 @@ +// PR c++/102305 +// { dg-do compile { target c++11 } } + +namespace std +{ + template + struct integral_constant + { + static constexpr _Tp value = __v; + typedef integral_constant<_Tp, __v> type; + }; + + template + constexpr _Tp integral_constant<_Tp, __v>::value; + + typedef integral_constant true_type; + typedef integral_constant false_type; + + template + using bool_constant = integral_constant; + + template + struct is_constructible + : public bool_constant<__is_constructible(_Tp, _Args...)> + { + }; +} + +template +struct A { + virtual ~A() = 0; +}; + +struct B { + virtual ~B() = 0; +}; + +static_assert(!std::is_constructible >::value, ""); +static_assert(!std::is_constructible::value, "");