From patchwork Tue May 17 22:08:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1632579 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=UQFu0sWA; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4L2qz430JTz9s2R for ; Wed, 18 May 2022 08:09:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82A6F3857426 for ; Tue, 17 May 2022 22:09:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 82A6F3857426 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1652825358; bh=pWHl+MOSTY8yvqt8BlgGuWlZNUF5VyaAc8/g+xjlRp8=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UQFu0sWA57xJw/Bm0ps7QtwRyaiM+g4s4cyrRve+wL124CKFXKsWcQ8anh4yb7mAy OrcjYpSbtoVLpd2au489UTurX9xTCIVFMol6NlfEEEJ1mScw702wZoVJRIzf8IFtge 9F8hqQlSvz8cAX1uqBmoCf5NAQv6BwkssegY01BQ= 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 131EB3858434 for ; Tue, 17 May 2022 22:08:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 131EB3858434 Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-141-yZWjs6l4PHa1Q85HYGNXug-1; Tue, 17 May 2022 18:08:57 -0400 X-MC-Unique: yZWjs6l4PHa1Q85HYGNXug-1 Received: by mail-qt1-f200.google.com with SMTP id h5-20020ac81385000000b002f3f91834ffso378931qtj.10 for ; Tue, 17 May 2022 15:08:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=pWHl+MOSTY8yvqt8BlgGuWlZNUF5VyaAc8/g+xjlRp8=; b=nMjbV33aRCT6thn4TSlVXMIvieChCsoSZOIZuyhyquv7kq29FhMse51YeXYc2tkenY TdVH+TJjClHa6a+n/bujiFSCl1CAng2LtkGBAGcwIuESLarHpmxSEzMAu0Zrd2S8OEbv j/iBgeLdTd24jZ7oj8MUBcH2flv6HdUIzRyDiVrDZeF59yF9X7AmqtvAsL4EavhuGhc4 N5dHZqYVIdLvNlQcseXX8YTTprwQVj2cMfNb8c4vB/z6HuXnuJM/7OK8pNmsi/pxaB+P R/rN0d+yMh2BKZd18dyvfoz4EiHo+Twh3yQbE/IhfEYPmMd40ZfoqS1S/91/UFdoq409 sDXg== X-Gm-Message-State: AOAM533yi7BFHNIhYKTXgY07rbtCsR3iRf67R4WjHtyAJcFBNc7F7svq glhsN+4G25tdLWWladEZYHZZ7tBLdnDSpk9jAGy18WsE+j9yrfSlsms68x606pzRw3Jma2p8VKr egMpuwMl8AE3eo8muB7Ukny8R1/7WxlM0FapJIy8d+r4hsLOOh/l4Ai/QiBSKVkohfQ== X-Received: by 2002:a05:6214:212a:b0:45b:7c0:7444 with SMTP id r10-20020a056214212a00b0045b07c07444mr22085315qvc.56.1652825336392; Tue, 17 May 2022 15:08:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/jbKta5YC1VPkK6YgSFpD7Fzg6kVkMUoaWv7ZM7Xir/XjBDkQvUQIzs/Filr6y/h8062LIw== X-Received: by 2002:a05:6214:212a:b0:45b:7c0:7444 with SMTP id r10-20020a056214212a00b0045b07c07444mr22085286qvc.56.1652825335982; Tue, 17 May 2022 15:08:55 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id u187-20020a372ec4000000b0069fc13ce1e2sm276165qkh.19.2022.05.17.15.08.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 May 2022 15:08:55 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: constexpr ref to array of array [PR102307] Date: Tue, 17 May 2022 18:08:53 -0400 Message-Id: <20220517220853.56246-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.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_LOW, 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The problem here is that first check_initializer calls build_aggr_init_full_exprs, which does overload resolution, but then in the case of failed constexpr throws away the result and does it again in build_functional_cast. But in the first overload resolution, reshape_init_array_1 decided to reuse the inner CONSTRUCTORs because tf_error is set, so we know we're committed. But the second pass gets confused by the CONSTRUCTORs with non-init-list types. Fixed by avoiding a second pass: instead, pass the call from build_aggr_init to build_cplus_new, which will turn it into a TARGET_EXPR. I don't bother to change the object argument because it will be replaced later in simplify_aggr_init_expr. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/102307 gcc/cp/ChangeLog: * decl.cc (check_initializer): Use build_cplus_new in case of constexpr failure. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/constexpr-array2.C: New test. --- gcc/cp/decl.cc | 17 ++++++++++++----- gcc/testsuite/g++.dg/cpp1z/constexpr-array2.C | 12 ++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/constexpr-array2.C base-commit: ed12749a3c9d9569a2c23df2e0db2136dcd3512d diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 5654bc754e6..381259cb9cf 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -7413,12 +7413,19 @@ check_initializer (tree decl, tree init, int flags, vec **cleanups) /* Declared constexpr or constinit, but no suitable initializer; massage init appropriately so we can pass it into store_init_value for the error. */ - if (CLASS_TYPE_P (type) - && (!init || TREE_CODE (init) == TREE_LIST)) + tree new_init = NULL_TREE; + if (!processing_template_decl + && TREE_CODE (init_code) == CALL_EXPR) + new_init = build_cplus_new (type, init_code, tf_none); + else if (CLASS_TYPE_P (type) + && (!init || TREE_CODE (init) == TREE_LIST)) + new_init = build_functional_cast (input_location, type, + init, tf_none); + if (new_init) { - init = build_functional_cast (input_location, type, - init, tf_none); - if (TREE_CODE (init) == TARGET_EXPR) + init = new_init; + if (TREE_CODE (init) == TARGET_EXPR + && !(flags & LOOKUP_ONLYCONVERTING)) TARGET_EXPR_DIRECT_INIT_P (init) = true; } init_code = NULL_TREE; diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-array2.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-array2.C new file mode 100644 index 00000000000..c30e3f2361d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-array2.C @@ -0,0 +1,12 @@ +// PR c++/102307 +// { dg-do compile { target c++11 } } + +#include +template struct Matrix { + constexpr Matrix(double const (&arr)[N][M]); // { dg-warning "never defined" } + constexpr Matrix(std::array, N> const &arr); +}; +int main() { + constexpr Matrix<2, 3> + mat {{ {1.0, 2.0, 3.0}, {4.0, 5.0, 6.0} }}; // { dg-error "before its definition" } +}