aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2022-09-12 14:14:24 -0400
committerJason Merrill <jason@redhat.com>2022-09-12 15:46:59 -0400
commit6bcca5f642eb950a3cef024ea49a35e4792306f6 (patch)
treeb3dd30c6c6ed9248c4b22d0a19a2711fa0c6e2a7 /gcc
parent936efcac733fe49e5ea9e636403e5941f24ff1b3 (diff)
downloadgcc-6bcca5f642eb950a3cef024ea49a35e4792306f6.zip
gcc-6bcca5f642eb950a3cef024ea49a35e4792306f6.tar.gz
gcc-6bcca5f642eb950a3cef024ea49a35e4792306f6.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.cc6
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist-array17.C37
2 files changed, 40 insertions, 3 deletions
diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc
index ad9c2f9..31e3e39 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 0000000..c4284a7
--- /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();
+}