aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2020-01-26 22:19:47 -0500
committerJason Merrill <jason@redhat.com>2020-01-27 15:02:52 -0500
commit8f25c39c454d7d3d323edf014a653649946352bd (patch)
treea92ba7747dfab3f83dc24a5e711c8e50346a7c47
parent1f2e84238c9f079747804026b6225ec8c1d0e4b7 (diff)
downloadgcc-8f25c39c454d7d3d323edf014a653649946352bd.zip
gcc-8f25c39c454d7d3d323edf014a653649946352bd.tar.gz
gcc-8f25c39c454d7d3d323edf014a653649946352bd.tar.bz2
c++: Fix array of char typedef in template (PR90966).
Since Martin Sebor's patch for PR 71625 to change braced array initializers to STRING_CST in some cases, we need to be ready for STRING_CST with types that are changed by tsubst. fold_convert doesn't know how to deal with STRING_CST, which is reasonable; we really shouldn't expect it to here. So let's handle STRING_CST separately. PR c++/90966 * pt.c (tsubst_copy) [STRING_CST]: Don't use fold_convert.
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/pt.c13
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist-array10.C14
3 files changed, 31 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b1bf4a0..44f3975 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,8 @@
+2020-01-27 Jason Merrill <jason@redhat.com>
+
+ PR c++/90966
+ * pt.c (tsubst_copy) [STRING_CST]: Don't use fold_convert.
+
2020-01-27 Iain Sandoe <iain@sandoe.co.uk>
PR c++/93443
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 45c204e..6e614d5 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -16772,7 +16772,6 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
case INTEGER_CST:
case REAL_CST:
- case STRING_CST:
case COMPLEX_CST:
{
/* Instantiate any typedefs in the type. */
@@ -16782,6 +16781,18 @@ tsubst_copy (tree t, tree args, tsubst_flags_t complain, tree in_decl)
return r;
}
+ case STRING_CST:
+ {
+ tree type = tsubst (TREE_TYPE (t), args, complain, in_decl);
+ r = t;
+ if (type != TREE_TYPE (t))
+ {
+ r = copy_node (t);
+ TREE_TYPE (r) = type;
+ }
+ return r;
+ }
+
case PTRMEM_CST:
/* These can sometimes show up in a partial instantiation, but never
involve template parms. */
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist-array10.C b/gcc/testsuite/g++.dg/cpp0x/initlist-array10.C
new file mode 100644
index 0000000..fb9e136
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist-array10.C
@@ -0,0 +1,14 @@
+// PR c++/90966
+// { dg-do compile { target c++11 } }
+
+template<typename I>
+void f()
+{
+ using S = signed char;
+ constexpr const S v[]{0};
+}
+
+int main()
+{
+ f<int>();
+}