From 7d510a821a48a208b224a0f5e73fb2a3e48a583e Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Mon, 2 Jan 2012 16:15:49 +0000 Subject: [PATCH] re PR c++/20140 (template function complains about "char-array initialized from wide string") /cp 2012-01-02 Paolo Carlini PR c++/20140 * typeck2.c (digest_init_r): Use copy_init when initializing an array of chars. /testsuite 2012-01-02 Paolo Carlini PR c++/20140 * g++.dg/template/init9.C: New. From-SVN: r182805 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck2.c | 6 +++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/template/init9.C | 12 ++++++++++++ 4 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/init9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index c6027213187..7b91727aca9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-01-02 Paolo Carlini + + PR c++/20140 + * typeck2.c (digest_init_r): Use copy_init when initializing + an array of chars. + 2012-01-01 Paolo Carlini PR c++/16603 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 4648e756481..a1b4274bdb1 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -902,7 +902,11 @@ digest_init_r (tree type, tree init, bool nested, int flags, } } - TREE_TYPE (init) = type; + if (type != TREE_TYPE (init)) + { + init = copy_node (init); + TREE_TYPE (init) = type; + } if (TYPE_DOMAIN (type) != 0 && TREE_CONSTANT (TYPE_SIZE (type))) { int size = TREE_INT_CST_LOW (TYPE_SIZE (type)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dd29a88d25e..ea547a3f70a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-01-02 Paolo Carlini + + PR c++/20140 + * g++.dg/template/init9.C: New. + 2012-01-02 Richard Sandiford * gcc.dg/memcpy-4.c: Add nomips16 attribute for MIPS targets. diff --git a/gcc/testsuite/g++.dg/template/init9.C b/gcc/testsuite/g++.dg/template/init9.C new file mode 100644 index 00000000000..d33c7da17b6 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/init9.C @@ -0,0 +1,12 @@ +// PR c++/20140 + +template void foo() +{ + unsigned char s[] = ""; +} + +int main() +{ + foo(); + foo(); +}