From patchwork Thu Mar 28 18:25:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1917549 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=d+EO6cnN; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V5Bnw3gKzz1yWr for ; Fri, 29 Mar 2024 05:26:43 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 4B6F7385842C for ; Thu, 28 Mar 2024 18:26:41 +0000 (GMT) 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.129.124]) by sourceware.org (Postfix) with ESMTPS id E8E7B3858D1E for ; Thu, 28 Mar 2024 18:26:19 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E8E7B3858D1E 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 E8E7B3858D1E Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711650382; cv=none; b=AaRFFWfvtSYJIsdHsoHPNvzU4lRLMcYciRlv6itLx39tSJ+NCXBWAve33JwSqlCZ5qe/6TSNj/NdUJtdlzFwl86j5xR+gqhuEMcUg7R31g7sprFiEqktSBsvciDuJH4uHFqj0uVJSWjGNvWvDYXoiILE7CZPeEtAMSxoJMkfDYY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1711650382; c=relaxed/simple; bh=GMQBwEaGK6JN08Q7XmqM1IwPJovnzOb5EVcKdQUfDJI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=SrdXtxUW4Id3qQ72ukHMVt1cqrQiHXO20zL20uPlgx1p1MLXF7/c+pxFvw/WSWrb/sXAvDfK91I0/5I+UoBAnZwrCOV8vLJN76Pd3Gu2eIhuOGZiEteLUFL9x7ynV7kjgZkcSREtTJ05d+NoNsic24HyDVRv0C1Oldl5LhsRwp4= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1711650379; 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: content-transfer-encoding:content-transfer-encoding; bh=hy17ojqfkC9g2KTxe+D2OH+Yjrg1WXaHMeuT13MdwsA=; b=d+EO6cnNA4Zn9DN8WBXi3foJWk2RIhdREUm3YFw8qvnxfblOG5TClOrv88FNzVxI9X57bD ss42/r0V9GW5+i89uqj1XJkQPwJX+sl1C/cqOA6p8zujAArlwK7TXFE9emjtEWHW8QRiki rjPtgCdVrYDxuwTM7SipDhpn1W1GvWY= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-455-PPM5LcycPheeTtBAl6PC5A-1; Thu, 28 Mar 2024 14:26:18 -0400 X-MC-Unique: PPM5LcycPheeTtBAl6PC5A-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-789db60eb39so134566185a.3 for ; Thu, 28 Mar 2024 11:26:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711650377; x=1712255177; 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=hy17ojqfkC9g2KTxe+D2OH+Yjrg1WXaHMeuT13MdwsA=; b=sAeV6u7+7HlHKAPWG5+61KTY1CuSsiS10zFBKAoYjYu4uUgVRZVKbJwCDq1Z/Oxn6E 6tzCyErxZpoY3jfV5sTspGsKU7Y5fKvJldzVr4UkyLk8rJrmgBXn5NNpovEeISf6RDYU j/HNHCT55nzDK6TulpNk6mUFNPPSRCIk3o8p5oYyjC6csIfUna8fRTTfRShlt5eInFQr nYvlIIpONf0UBJhGE2BgOlB7Cxc9uY7UFzm1ZK/c3jI+xPjjLqOPlHIkw2cBITo2lRAr C27MuckWx9253gN2M9IH+nZAZumyISr3iQQQzQg0Fbd8tqc63EpBsjwrt3a9CSMXRDG8 NjBg== X-Gm-Message-State: AOJu0YzIhPvM774XfZoco/K6r3AKFWDIypFRT1DS4Y8jC/9m+NRMiFh1 ETfTg7QNJ/ew8NkVFxpuAkY2DAgK4zWDKqw3e+vUFdUvPwBVmgrJBRMgT9D7FRnQoHiEaNBieug He/Xhohn4Jz5rs1VTk3iHNEN2HkcSylURMbVf2jVW1bjukh0xQHrt67kBSn6EhWRLJAb3L2b1po oGyOk03UsHXiNlP1qgHae9miAFqX35eWlwkdM= X-Received: by 2002:a05:620a:384a:b0:788:3101:b1f0 with SMTP id po10-20020a05620a384a00b007883101b1f0mr253180qkn.64.1711650377432; Thu, 28 Mar 2024 11:26:17 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgbdda+/ueVowfRZy/8PKTmskCZRcpjJEw5IusIbjE+ksFK4s9eTObyG6OYGKXmJMNBzVz/g== X-Received: by 2002:a05:620a:384a:b0:788:3101:b1f0 with SMTP id po10-20020a05620a384a00b007883101b1f0mr253156qkn.64.1711650377010; Thu, 28 Mar 2024 11:26:17 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id wx37-20020a05620a5a6500b00788402160besm721103qkn.128.2024.03.28.11.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 11:26:16 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Cc: Jonathan Wakely Subject: [PATCH] c++: __is_constructible ref binding [PR100667] Date: Thu, 28 Mar 2024 14:25:03 -0400 Message-ID: <20240328182615.28173-1-jason@redhat.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 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_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- The requirement that a type argument be complete is excessive in the case of direct reference binding to the same type, which does not rely on any properties of the type. This is LWG 2939. PR c++/100667 gcc/cp/ChangeLog: * semantics.cc (same_type_ref_bind_p): New. (finish_trait_expr): Use it. gcc/testsuite/ChangeLog: * g++.dg/ext/is_constructible8.C: New test. --- gcc/cp/semantics.cc | 54 +++++++++++++++++--- gcc/testsuite/g++.dg/ext/is_constructible8.C | 31 +++++++++++ 2 files changed, 78 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/is_constructible8.C base-commit: bbb7c513dddc5c9b2d5e9b78bc1c2f85a0cfe07e diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index adb1ba48d29..9838331d2a9 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -12607,6 +12607,45 @@ check_trait_type (tree type, int kind = 1) return true; } +/* True iff the conversion (if any) would be a direct reference + binding, not requiring complete types. This is LWG2939. */ + +static bool +same_type_ref_bind_p (cp_trait_kind kind, tree type1, tree type2) +{ + tree from, to; + switch (kind) + { + /* These put the target type first. */ + case CPTK_IS_CONSTRUCTIBLE: + case CPTK_IS_NOTHROW_CONSTRUCTIBLE: + case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: + case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: + case CPTK_REF_CONVERTS_FROM_TEMPORARY: + to = type1; + from = type2; + break; + + /* These put it second. */ + case CPTK_IS_CONVERTIBLE: + case CPTK_IS_NOTHROW_CONVERTIBLE: + to = type2; + from = type1; + break; + + default: + gcc_unreachable (); + } + + if (TREE_CODE (to) != REFERENCE_TYPE || !from) + return false; + if (TREE_CODE (from) == TREE_VEC && TREE_VEC_LENGTH (from) == 1) + from = TREE_VEC_ELT (from, 0); + return (TYPE_P (from) + && (same_type_ignoring_top_level_qualifiers_p + (non_reference (to), non_reference (from)))); +} + /* Process a trait expression. */ tree @@ -12666,20 +12705,21 @@ finish_trait_expr (location_t loc, cp_trait_kind kind, tree type1, tree type2) return error_mark_node; break; - case CPTK_IS_ASSIGNABLE: case CPTK_IS_CONSTRUCTIBLE: - if (!check_trait_type (type1)) - return error_mark_node; - break; - case CPTK_IS_CONVERTIBLE: - case CPTK_IS_NOTHROW_ASSIGNABLE: case CPTK_IS_NOTHROW_CONSTRUCTIBLE: case CPTK_IS_NOTHROW_CONVERTIBLE: - case CPTK_IS_TRIVIALLY_ASSIGNABLE: case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE: case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY: case CPTK_REF_CONVERTS_FROM_TEMPORARY: + /* Don't check completeness for direct reference binding. */; + if (same_type_ref_bind_p (kind, type1, type2)) + break; + gcc_fallthrough (); + + case CPTK_IS_ASSIGNABLE: + case CPTK_IS_NOTHROW_ASSIGNABLE: + case CPTK_IS_TRIVIALLY_ASSIGNABLE: if (!check_trait_type (type1) || !check_trait_type (type2)) return error_mark_node; diff --git a/gcc/testsuite/g++.dg/ext/is_constructible8.C b/gcc/testsuite/g++.dg/ext/is_constructible8.C new file mode 100644 index 00000000000..a27ec6eddd7 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/is_constructible8.C @@ -0,0 +1,31 @@ +// PR c++/100667 +// { dg-do compile { target c++11 } } + +struct T; + +#define SA(X) static_assert ((X), #X); + +SA (__is_constructible(T&&, T)); +SA (__is_constructible(const T&, T)); +SA (!__is_constructible(T&, T)); +SA (__is_nothrow_constructible(T&&, T)); +SA (__is_nothrow_constructible(const T&, T)); +SA (!__is_nothrow_constructible(T&, T)); +SA (__is_trivially_constructible(T&&, T)); +SA (__is_trivially_constructible(const T&, T)); +SA (!__is_trivially_constructible(T&, T)); + +SA (__is_convertible(T, T&&)); +SA (__is_convertible(T, const T&)); +SA (!__is_convertible(T, T&)); +SA (__is_nothrow_convertible(T, T&&)); +SA (__is_nothrow_convertible(T, const T&)); +SA (!__is_nothrow_convertible(T, T&)); + +// All false because either the conversion fails or it doesn't bind a temporary +SA (!__reference_constructs_from_temporary (T&&, T)); +SA (!__reference_constructs_from_temporary (const T&, T)); +SA (!__reference_constructs_from_temporary (T&, T)); +SA (!__reference_converts_from_temporary (T&&, T)); +SA (!__reference_converts_from_temporary (const T&, T)); +SA (!__reference_converts_from_temporary (T&, T));