OSDN Git Service

/cp
authorpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 2 Jan 2012 16:15:49 +0000 (16:15 +0000)
committerpaolo <paolo@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 2 Jan 2012 16:15:49 +0000 (16:15 +0000)
2012-01-02  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/20140
* typeck2.c (digest_init_r): Use copy_init when initializing
an array of chars.

/testsuite
2012-01-02  Paolo Carlini  <paolo.carlini@oracle.com>

PR c++/20140
* g++.dg/template/init9.C: New.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182805 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/template/init9.C [new file with mode: 0644]

index c602721..7b91727 100644 (file)
@@ -1,3 +1,9 @@
+2012-01-02  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/20140
+       * typeck2.c (digest_init_r): Use copy_init when initializing
+       an array of chars.
+
 2012-01-01  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/16603
index 4648e75..a1b4274 100644 (file)
@@ -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));
index dd29a88..ea547a3 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-02  Paolo Carlini  <paolo.carlini@oracle.com>
+
+       PR c++/20140
+       * g++.dg/template/init9.C: New.
+
 2012-01-02  Richard Sandiford  <rdsandiford@googlemail.com>
 
        * 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 (file)
index 0000000..d33c7da
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/20140
+
+template<typename T> void foo()
+{
+  unsigned char s[] = "";
+}
+
+int main()
+{
+  foo<char>();
+  foo<int>();
+}