From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1663012002; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=i3bi0Wz2CCnlkZ/TiKJ6njPDdBCU92BpucD5axju3EA=; b=OIScWto4YoZhdEYQrcrmVxxFVB1TdAPU9msHise42p3YHnScBnUQz9zBpn7kVOivjwTsEz 6yg64MxP+wVwG2IAwQKTf8MauLdqUasyK1bADRLVUqsSqtvvcO4sZlBgaVD0BBroQRLrnu 5lQ8SIeSa5BKzqPJRq/p2ZiTVrYhQRA= 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-Google-Smtp-Source: AA6agR4NuY+dbCe0DPLQ2HdidnZLGlwWGAzFLir1ZC29OllGxClsmxj9sq1uFOZm6PQSzN8KCJIiWg== 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) From: Jason Merrill 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 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(); +} base-commit: 7c989a8ed47228bdd494a2f0d1f6fdd325f953d7 -- 2.31.1