This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: PATCH to build_array_type_1 for c++/55032 (array template argument)
- From: Jason Merrill <jason at redhat dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Thu, 06 Dec 2012 11:07:06 -0500
- Subject: RFA: PATCH to build_array_type_1 for c++/55032 (array template argument)
In this PR, strip_typedefs rebuilds an array type without any typedefs
and then gets confused when the rebuilt type has a different TYPE_ALIGN
than the typedef-using type. This happens because the rebuilt type was
found in the type_hash_canon hash table, and was originally built before
the element type was complete, so the rebuilt type hasn't been laid out
yet. Since we already do layout_type in build_array_type_1, it seems
appropriate that it should always return a laid out type, so this patch
causes us to repeat the layout if we found the type already in the hash
table.
Tested x86_64-pc-linux-gnu. OK for 4.7 and 4.8?
commit 429af9226fcba2450a8fbfcfba85801a38d0d129
Author: Jason Merrill <jason@redhat.com>
Date: Thu Dec 6 10:21:25 2012 -0500
PR c++/55032
* tree.c (build_array_type_1): Re-layout if we found it in the
hash table.
diff --git a/gcc/tree.c b/gcc/tree.c
index 7cacb2a..429db49 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -7505,7 +7505,12 @@ build_array_type_1 (tree elt_type, tree index_type, bool shared)
hashval_t hashcode = iterative_hash_object (TYPE_HASH (elt_type), 0);
if (index_type)
hashcode = iterative_hash_object (TYPE_HASH (index_type), hashcode);
+ tree old_t = t;
t = type_hash_canon (hashcode, t);
+ if (t != old_t)
+ /* Lay it out again in case the element type has been completed since
+ the array was added to the hash table. */
+ layout_type (t);
}
if (TYPE_CANONICAL (t) == t)
diff --git a/gcc/testsuite/g++.dg/template/array24.C b/gcc/testsuite/g++.dg/template/array24.C
new file mode 100644
index 0000000..07879d2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/array24.C
@@ -0,0 +1,22 @@
+// PR c++/55032
+
+template<typename T>
+struct vec3t {
+ T c[3];
+};
+
+typedef vec3t<float> vec3;
+
+class Bounds {
+ public:
+ Bounds(const vec3 bb[2]);
+ void foo(const vec3 & v) { v.c[0]; }
+};
+
+template<typename T>
+void work(T& value);
+
+void foo() {
+ vec3 bb[2];
+ work(bb);
+}