Patchwork [C++] Fix a regression from build_cplus_array_type recent change (PR c++/54038)

login
register
mail settings
Submitter Jakub Jelinek
Date July 20, 2012, 1:26 p.m.
Message ID <20120720132634.GL4807@tucnak.redhat.com>
Download mbox | patch
Permalink /patch/172276/
State New
Headers show

Comments

Jakub Jelinek - July 20, 2012, 1:26 p.m.
Hi!

As detailed in the PR, I believe we should only add c into m's variant chain
if m's element type is the main variant of c's element type.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk/4.7?

2012-07-20  Jakub Jelinek  <jakub@redhat.com>

	PR c++/54038
	* tree.c (build_cplus_array_type): Don't change TYPE_CANONICAL's
	TYPE_MAIN_VARIANT if it's element type's TYPE_MAIN_VARIANT is not
	m's element type.

	* g++.dg/other/array7.C: New test.


	Jakub

Patch

--- gcc/cp/tree.c.jj	2012-07-19 22:43:19.000000000 +0200
+++ gcc/cp/tree.c	2012-07-20 12:54:41.014662931 +0200
@@ -814,7 +814,8 @@  build_cplus_array_type (tree elt_type, t
 
       /* If we built a new array type for TYPE_CANONICAL, add
 	 that to the list of variants as well.  */
-      if (c && c != t && TYPE_MAIN_VARIANT (c) != m)
+      if (c && c != t && TYPE_MAIN_VARIANT (c) != m
+	  && TYPE_MAIN_VARIANT (TREE_TYPE (c)) == TYPE_MAIN_VARIANT (elt_type))
 	{
 	  TYPE_MAIN_VARIANT (c) = m;
 	  TYPE_NEXT_VARIANT (c) = t;
--- gcc/testsuite/g++.dg/other/array7.C.jj	2012-07-20 12:58:26.118439241 +0200
+++ gcc/testsuite/g++.dg/other/array7.C	2012-07-20 12:56:50.000000000 +0200
@@ -0,0 +1,9 @@ 
+// PR c++/54038
+
+extern const char *const v[];
+typedef char T;
+void foo (const T *const[]);
+struct A
+{
+  static const char *const a[];
+};