From patchwork Mon Sep 12 19:46:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1173 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp2027005wrt; Mon, 12 Sep 2022 12:47:52 -0700 (PDT) X-Google-Smtp-Source: AA6agR5FDY5WyXErZoiTRKVufhVXExtiAuuTLjVJpZzbE8KVTgT5F0cyAAcCsSbtGj8CQYB6oFVC X-Received: by 2002:a17:907:a04e:b0:770:79f4:f520 with SMTP id gz14-20020a170907a04e00b0077079f4f520mr19217750ejc.730.1663012072391; Mon, 12 Sep 2022 12:47:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663012072; cv=none; d=google.com; s=arc-20160816; b=paZcPoI3itAWBX5wrqYDTVTT0/MWeZcp9s1l4JGpn7q2M3qFAgjY0wKY9wcHB8O7d1 q6re+3czcRM468yX6vkErK/gZdITnOxmi/pIJYKO7J/XCM3bDTa3HG+li6ah4Czeh/PQ VnldMstDdp6f/F9Ew5XH2WXtFLiEbvtAj9NkpanNEbP6ORu75x88+5P0MSENBijWuYCs FGEvOvtY0nTwY/nsWV9Cux4508C0paEz69wWrlb6ML/UFQbsBPQoEpFJ0BwZB1N6bTYu phqqerwf3l6LdSoadzUiO5KGUHXNxZR11XMLo59T37HD9j78UN4ZbvibR88E1/4ahs6k H/GQ== 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=i3bi0Wz2CCnlkZ/TiKJ6njPDdBCU92BpucD5axju3EA=; b=l6frgoC2x3tM7zkecDFV15dDWfZ14g8MeiQebUvlHElRHQ+2/iOIcAOOf9oFpnm/Lz HmWpWS6Dz/Ido/5SHthb/c8H0EiwB/kVDg2e0J0crwPM9APbzS/c2vn8jpFnh0tBV9PG xc51NI8pRqXSwHaNe+DiX9Rn/OCNmxGZvSwQtHylPoZOe211RdGwdjqWX+8dOpSha1eP X7GC6gtc9MXqQtXbFcJFci3gt2YVyihda6GYhr0McGiSnm77StK9U05aJR+DtbTX+pup OL0CofPU8QBOtUq0aJM/Bcp8M5CVRs14t/80R2bbKQrTNnqA+9R5RooRTYSvGvezRmbJ LaaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=bkjVPHOM; 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 q10-20020a056402518a00b00450f21d5199si5503253edd.310.2022.09.12.12.47.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 12:47:52 -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=bkjVPHOM; 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 227963850854 for ; Mon, 12 Sep 2022 19:47:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 227963850854 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663012048; bh=i3bi0Wz2CCnlkZ/TiKJ6njPDdBCU92BpucD5axju3EA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bkjVPHOMLTJzHjEwVf8TZPBtxg6wcHbZHUf3p+Q3gQilrHy0UoSLUGUm3527/Hz7v bjQkT84JMIIo828wCXQIfLXHt3XE07dtTMZZJivXUz/ohYNHmCBGcY0tYR4IO2atFt yNWZt0jNh4PMHCMIOyxvxW2z41OddcACKTaVmheI= 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 CE6B93858403 for ; Mon, 12 Sep 2022 19:46:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org CE6B93858403 Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-21-VymJntJkOGmxmCuVovqVTQ-1; Mon, 12 Sep 2022 15:46:40 -0400 X-MC-Unique: VymJntJkOGmxmCuVovqVTQ-1 Received: by mail-qk1-f200.google.com with SMTP id bj2-20020a05620a190200b006bba055ab6eso8238749qkb.12 for ; Mon, 12 Sep 2022 12:46:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=i3bi0Wz2CCnlkZ/TiKJ6njPDdBCU92BpucD5axju3EA=; b=ARLVVgOmGt/eKmkJ6omDtn18vdSj/jRq6/pKC00akRMLNZrj4WPhWdb+JnpXA2j9jc 69ilhAzw/X7tMOAQn6xk63UgehWSxIzU5crHSGRKelulm4Sa4KNNovsM8TK1rQAcAjUH upwpT87jqRzrNBydAMj6qhEjggCrbmTlepsZCvBq8Uai3vUfImLdY7zQGoDBK80i+cNA QpXW46pew6MYqpR5n/A/mRQ9VXsPaw0J+xVip4LfJ6ShaiiLv76xvrZNKx6zBaXM/Jq/ 95iMCaPM87K6rTB2wScxdnsq8tOlfb3uxADbL9D4eIYYJpwgSZ11TrJX+le7eNl9YFzA O6pg== X-Gm-Message-State: ACgBeo3Ak7b08unG0guL0s+XFcYy+K2d91wv5bj8rWubf4qWvJsV0gBh 3caWYvji1kJ5Up5xdTx+D+NtMwvOzLKKNY4Hg+KmRhfcgbR67G77fEulaaaJ3W2spg0XYMPzLt2 98n5cq1BjV1hzbJ2M6IAPF1b+Mbsv2F28YwNqnOXeWFgXrqvpoBusF9t20sKUOCbDuQ== X-Received: by 2002:ac8:5f92:0:b0:344:9d67:ff70 with SMTP id j18-20020ac85f92000000b003449d67ff70mr25377915qta.96.1663011999710; Mon, 12 Sep 2022 12:46:39 -0700 (PDT) X-Received: by 2002:ac8:5f92:0:b0:344:9d67:ff70 with SMTP id j18-20020ac85f92000000b003449d67ff70mr25377878qta.96.1663011999108; Mon, 12 Sep 2022 12:46:39 -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 bn42-20020a05620a2aea00b006baed8f3a2esm7717703qkb.103.2022.09.12.12.46.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 12:46:38 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: cast to array of unknown bound [PR93259] Date: Mon, 12 Sep 2022 15:46:36 -0400 Message-Id: <20220912194636.3441627-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743794546518188670?= X-GMAIL-MSGID: =?utf-8?q?1743794546518188670?= We already know to treat a variable of array-of-unknown-bound type as dependent, we should do the same for arr{}. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/93259 gcc/cp/ChangeLog: * pt.cc (type_dependent_expression_p): Treat a compound literal of array-of-unknown-bound type like a variable. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/initlist-array17.C: New test. --- gcc/cp/pt.cc | 6 +-- gcc/testsuite/g++.dg/cpp0x/initlist-array17.C | 37 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/initlist-array17.C base-commit: 7c989a8ed47228bdd494a2f0d1f6fdd325f953d7 diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index ad9c2f9b180..31e3e391098 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -28082,11 +28082,11 @@ type_dependent_expression_p (tree expression) If the array has no length and has an initializer, it must be that we couldn't determine its length in cp_complete_array_type because it is dependent. */ - if (VAR_P (expression) + if (((VAR_P (expression) && DECL_INITIAL (expression)) + || COMPOUND_LITERAL_P (expression)) && TREE_TYPE (expression) != NULL_TREE && TREE_CODE (TREE_TYPE (expression)) == ARRAY_TYPE - && !TYPE_DOMAIN (TREE_TYPE (expression)) - && DECL_INITIAL (expression)) + && !TYPE_DOMAIN (TREE_TYPE (expression))) return true; /* Pull a FUNCTION_DECL out of a BASELINK if we can. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array17.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array17.C new file mode 100644 index 00000000000..c4284a7b391 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array17.C @@ -0,0 +1,37 @@ +// PR c++/93259 +// { dg-do compile { target c++11 } } + +template struct is_same; +template struct is_same { }; + +using Array = int[]; + +template +void bar1(Ts ...) +{ + auto && array = Array{ 1, 2, 3 }; + + is_same{}; // this fails, deduces array as int (&&) [] +} + +template +void bar2() +{ + auto && array = Array{ 1, 2, 3 }; + + is_same{}; // this fails, deduces array as int (&&) [] +} + +void bar3() +{ + auto && array = Array{ 1, 2, 3 }; + + is_same{}; // OK +} + +int main() +{ + bar1(1, 2, 3); + bar2(); + bar3(); +}