From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 16E25385C335; Mon, 12 Sep 2022 19:47:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 16E25385C335 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1663012026; bh=ZygqlcJB/Jyux2XhKDao3aXQK/8ulqTRVSpsr7WeFDU=; h=From:To:Subject:Date:From; b=e223NhRk0qM6aGrHTCKykWyFSOYH1h2KZxPZadlBhttV6pxgYaM7Rm2gZ4rsCJYLO GyYep44UMhKDm+0UEF0NRc8smpf90sxsmGDKJi3w7qWR5LbKqyK20k+TtiJphqdFfT qFzdaE18bg+T/i9C1CLdL7+LdpbeaZ704gxnKKF8= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2631] c++: cast to array of unknown bound [PR93259] X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: 936efcac733fe49e5ea9e636403e5941f24ff1b3 X-Git-Newrev: 6bcca5f642eb950a3cef024ea49a35e4792306f6 Message-Id: <20220912194706.16E25385C335@sourceware.org> Date: Mon, 12 Sep 2022 19:47:06 +0000 (GMT) List-Id: https://gcc.gnu.org/g:6bcca5f642eb950a3cef024ea49a35e4792306f6 commit r13-2631-g6bcca5f642eb950a3cef024ea49a35e4792306f6 Author: Jason Merrill Date: Mon Sep 12 14:14:24 2022 -0400 c++: cast to array of unknown bound [PR93259] We already know to treat a variable of array-of-unknown-bound type as dependent, we should do the same for arr{}. 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. Diff: --- gcc/cp/pt.cc | 6 ++--- gcc/testsuite/g++.dg/cpp0x/initlist-array17.C | 37 +++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) 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(); +}