From patchwork Fri Jan 10 11:46:43 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 104470 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 A07503858D34 for ; Fri, 10 Jan 2025 11:47:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A07503858D34 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=TFAh54j1 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 ESMTP id 4ACAC3858D34 for ; Fri, 10 Jan 2025 11:46:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4ACAC3858D34 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 4ACAC3858D34 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=1736509612; cv=none; b=t99/5ZOts07ewUXlDCCJiqVedvCFVi5PiBafBkFxF/MzB3qKAFnvxCJo3tJDWFcXKGyXQm0xPvpx9je0Yu4/FkTo3bpWonvasLVjbMhR4PcWRddju6esy75qkEWy5e6Mgm0tK18DwDCCNbI+l8/ueH/gtYQYBKIO8L8DtOTjGlQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736509612; c=relaxed/simple; bh=3MgmU8g/w0BtBROOAZhmKnAn0qJXo/4lgQuJ8z9+arQ=; h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version; b=lbqkLV4iTAhtf3RBjT8E0mGs5IGb3Ig7hRC/Eh49h1HUiC0N+0+MDxGsULc1fM9vSjzOkiLJMJjz1O1NAbIVT2IP41omsfLt2Hgl/obxmYPJJgcd4A1ZCNk+5P+0nUilpLzyZ7LSw8HyQgufgfsan6HoJ0Lr9XN5uFF+jzrV7hQ= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4ACAC3858D34 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736509611; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=Udkdxiy45/adKgJKwqV9GxdVnQb1Sui37w5JPG4L/IU=; b=TFAh54j1FaHEKjWnCTP/yxEQGk8LMIt8M95wXlJ8N+ocDvAfI4yYbIW5e6Gsot4f2jyxYQ CfRB6x9KOd8ybgg3CmuRLXNOD92bjAfXXWFTBiSStBGb71nV6AhfqCeClRQOSUsLRN1pKX FjC0JUoe3rYgoq7yDM3mAaGgvR09P5Y= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-647-XL38HqCaOCmEui0AU43SSQ-1; Fri, 10 Jan 2025 06:46:50 -0500 X-MC-Unique: XL38HqCaOCmEui0AU43SSQ-1 X-Mimecast-MFC-AGG-ID: XL38HqCaOCmEui0AU43SSQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9DD5B19560B2 for ; Fri, 10 Jan 2025 11:46:48 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.45.224.5]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id F1FD4195E3D9; Fri, 10 Jan 2025 11:46:47 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 50ABkit8250144 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 10 Jan 2025 12:46:44 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 50ABki2a250143; Fri, 10 Jan 2025 12:46:44 +0100 Date: Fri, 10 Jan 2025 12:46:43 +0100 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Handle RAW_DATA_CST in unify [PR118390] Message-ID: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: jAJ7W1twiHNzzDBTri-k4yEtBgmJE3u5hskNdCA8FXg_1736509609 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, KAM_SHORT, RCVD_IN_DNSWL_NONE, SCC_10_SHORT_WORD_LINES, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=no 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: , Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Hi! The following patch on top of https://gcc.gnu.org/pipermail/gcc-patches/2025-January/673177.html (in review currently) https://gcc.gnu.org/pipermail/gcc-patches/2024-December/672055.html (acked but waiting for the former) https://gcc.gnu.org/pipermail/gcc-patches/2025-January/672438.html https://gcc.gnu.org/pipermail/gcc-patches/2025-January/672496.html (waiting for review) uses the new function introduced in the second patch to fix up unify deduction of array sizes. Ok for trunk? 2025-01-10 Jakub Jelinek PR c++/118390 * cp-tree.h (count_ctor_elements): Declare. * call.cc (count_ctor_elements): No longer static. * pt.cc (unify): Use count_ctor_elements instead of CONSTRUCTOR_NELTS. * g++.dg/cpp/embed-20.C: New test. * g++.dg/cpp0x/pr118390.C: New test. Jakub --- gcc/cp/cp-tree.h.jj 2025-01-10 11:47:58.478841366 +0100 +++ gcc/cp/cp-tree.h 2025-01-10 12:40:51.898875583 +0100 @@ -6815,6 +6815,7 @@ extern tree type_decays_to (tree); extern tree extract_call_expr (tree); extern tree build_trivial_dtor_call (tree, bool = false); extern tristate ref_conv_binds_to_temporary (tree, tree, bool = false); +extern unsigned HOST_WIDE_INT count_ctor_elements (tree); extern tree build_user_type_conversion (tree, tree, int, tsubst_flags_t); extern tree build_new_function_call (tree, vec **, --- gcc/cp/call.cc.jj 2025-01-10 11:49:42.155399433 +0100 +++ gcc/cp/call.cc 2025-01-10 12:40:12.906413343 +0100 @@ -4333,7 +4333,7 @@ has_non_trivial_temporaries (tree expr) /* Return number of initialized elements in CTOR. */ -static unsigned HOST_WIDE_INT +unsigned HOST_WIDE_INT count_ctor_elements (tree ctor) { unsigned HOST_WIDE_INT len = 0; --- gcc/cp/pt.cc.jj 2025-01-10 10:32:28.801729684 +0100 +++ gcc/cp/pt.cc 2025-01-10 12:41:19.801491043 +0100 @@ -25064,7 +25064,7 @@ unify (tree tparms, tree targs, tree par && deducible_array_bound (TYPE_DOMAIN (parm))) { /* Also deduce from the length of the initializer list. */ - tree max = size_int (CONSTRUCTOR_NELTS (arg)); + tree max = size_int (count_ctor_elements (arg)); tree idx = compute_array_index_type (NULL_TREE, max, tf_none); if (idx == error_mark_node) return unify_invalid (explain_p); --- gcc/testsuite/g++.dg/cpp/embed-20.C.jj 2025-01-10 12:30:08.578762083 +0100 +++ gcc/testsuite/g++.dg/cpp/embed-20.C 2025-01-10 12:29:29.882296675 +0100 @@ -0,0 +1,14 @@ +// PR c++/118390 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template +constexpr int +foo (const T (&x)[N]) +{ + return N; +} + +static_assert (foo ({ + #embed __FILE__ limit (64) +}) == 64, ""); --- gcc/testsuite/g++.dg/cpp0x/pr118390.C.jj 2025-01-10 12:30:59.748055186 +0100 +++ gcc/testsuite/g++.dg/cpp0x/pr118390.C 2025-01-10 12:31:34.681572583 +0100 @@ -0,0 +1,23 @@ +// PR c++/118390 +// { dg-do compile { target c++11 } } +// { dg-options "" } + +template +constexpr int +foo (const T (&x)[N]) +{ + return N; +} + +static_assert (foo ({ + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, + 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +}) == 160, "");