From ce262374bac8eab27b12ec1163ac4c79661d6402 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 20 Jul 2012 16:11:42 +0000 Subject: [PATCH] PR c++/54038 * tree.c (build_cplus_array_type): Use build_cplus_array_type to build canonical array type rather than mess with its TYPE_*_VARIANT. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@189719 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/tree.c | 23 ++++++++++++----------- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/other/array7.C | 9 +++++++++ 4 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 gcc/testsuite/g++.dg/other/array7.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 647b719c734..07ed0a0a5eb 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2012-07-20 Jason Merrill + + PR c++/54038 + * tree.c (build_cplus_array_type): Use build_cplus_array_type to build + canonical array type rather than mess with its TYPE_*_VARIANT. + 2012-07-19 Jason Merrill PR c++/54026 diff --git a/gcc/cp/tree.c b/gcc/cp/tree.c index 3c7bbb132f3..83b8ca7ad1c 100644 --- a/gcc/cp/tree.c +++ b/gcc/cp/tree.c @@ -795,7 +795,18 @@ build_cplus_array_type (tree elt_type, tree index_type) } } else - t = build_array_type (elt_type, index_type); + { + if (!TYPE_STRUCTURAL_EQUALITY_P (elt_type) + && !(index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)) + && (TYPE_CANONICAL (elt_type) != elt_type + || (index_type && TYPE_CANONICAL (index_type) != index_type))) + /* Make sure that the canonical type is on the appropriate + variants list. */ + build_cplus_array_type + (TYPE_CANONICAL (elt_type), + index_type ? TYPE_CANONICAL (index_type) : index_type); + t = build_array_type (elt_type, index_type); + } /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the element type as well, so fix it up if needed. */ @@ -803,7 +814,6 @@ build_cplus_array_type (tree elt_type, tree index_type) { tree m = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), index_type); - tree c = TYPE_CANONICAL (t); if (TYPE_MAIN_VARIANT (t) != m) { @@ -811,15 +821,6 @@ build_cplus_array_type (tree elt_type, tree index_type) TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); TYPE_NEXT_VARIANT (m) = 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) - { - TYPE_MAIN_VARIANT (c) = m; - TYPE_NEXT_VARIANT (c) = t; - TYPE_NEXT_VARIANT (m) = c; - } } /* Push these needs up so that initialization takes place diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 56aace37ff4..6759427b466 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-07-20 Jason Merrill + + PR c++/54038 + * g++.dg/other/array7.C: New. + 2012-07-20 Steven Bosscher * gcc.dg/tree-prof/update-loopch.c: Look for counts on the dumps of diff --git a/gcc/testsuite/g++.dg/other/array7.C b/gcc/testsuite/g++.dg/other/array7.C new file mode 100644 index 00000000000..72322f06308 --- /dev/null +++ b/gcc/testsuite/g++.dg/other/array7.C @@ -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[]; +}; -- 2.11.4.GIT