From: Jason Merrill <jason@redhat.com>
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 [thread overview]
Message-ID: <20220912194636.3441627-1-jason@redhat.com> (raw)
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 <class T, class U> struct is_same;
+template <class T> struct is_same<T,T> { };
+
+using Array = int[];
+
+template <typename ...Ts>
+void bar1(Ts ...)
+{
+ auto && array = Array{ 1, 2, 3 };
+
+ is_same<int (&&)[3], decltype(array)>{}; // this fails, deduces array as int (&&) []
+}
+
+template <typename T>
+void bar2()
+{
+ auto && array = Array{ 1, 2, 3 };
+
+ is_same<int (&&)[3], decltype(array)>{}; // this fails, deduces array as int (&&) []
+}
+
+void bar3()
+{
+ auto && array = Array{ 1, 2, 3 };
+
+ is_same<int (&&)[3], decltype(array)>{}; // OK
+}
+
+int main()
+{
+ bar1<int>(1, 2, 3);
+ bar2<int>();
+ bar3();
+}
base-commit: 7c989a8ed47228bdd494a2f0d1f6fdd325f953d7
--
2.31.1
reply other threads:[~2022-09-12 19:46 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220912194636.3441627-1-jason@redhat.com \
--to=jason@redhat.com \
--cc=gcc-patches@gcc.gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).