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 <ja...@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. --- 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[]; +}; Jakub