diff mbox

[RFH,/] PR 20140

Message ID 4F01CD62.1080709@oracle.com
State New
Headers show

Commit Message

Paolo Carlini Jan. 2, 2012, 3:29 p.m. UTC
On 01/02/2012 04:06 PM, Jason Merrill wrote:
> On 01/02/2012 08:25 AM, Paolo Carlini wrote:
>> Bad, because currently many
>> circumstances in which we do TREE_TYPE (init) = type are in fact benign:
> I don't think they are benign.  Even when types are equivalent, we 
> need to convert between them, as several things in the back end rely 
> on pointer equality, and we don't want different instantiations 
> changing the type in subtly different ways.
Ok. Then yesterday's patch certainly works and you already approved. The 
below is what I'm going to apply.

Thanks,
Paolo.

////////////////////
/cp
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.
diff mbox

Patch

Index: testsuite/g++.dg/template/init9.C
===================================================================
--- testsuite/g++.dg/template/init9.C	(revision 0)
+++ testsuite/g++.dg/template/init9.C	(revision 0)
@@ -0,0 +1,12 @@ 
+// PR c++/20140
+
+template<typename T> void foo()
+{
+  unsigned char s[] = "";
+}
+
+int main()
+{
+  foo<char>();
+  foo<int>();
+}
Index: cp/typeck2.c
===================================================================
--- cp/typeck2.c	(revision 182784)
+++ cp/typeck2.c	(working copy)
@@ -902,7 +902,11 @@  digest_init_r (tree type, tree init, bool nested,
 		}
 	    }
 
-	  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));