re PR c++/55804 (GCC omits required call to constructor)
authorJason Merrill <jason@redhat.com>
Wed, 2 Jan 2013 19:03:04 +0000 (14:03 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 2 Jan 2013 19:03:04 +0000 (14:03 -0500)
PR c++/55804
PR c++/55032
PR c++/55245
* tree.c (build_array_type_1): Revert earlier change.
* cp/tree.c (build_cplus_array_type): Copy layout information
to main variant if necessary.

From-SVN: r194811

gcc/ChangeLog
gcc/cp/ChangeLog
gcc/cp/tree.c
gcc/testsuite/g++.dg/init/array33.C [new file with mode: 0644]
gcc/tree.c

index e8b7a349353fb42f9aa0597e38e8faef220a298b..4b3834b29237ccef6a9897dac99c6e3ce04c6271 100644 (file)
@@ -1,3 +1,8 @@
+2013-01-02  Jason Merrill  <jason@redhat.com>
+
+       PR c++/55804
+       * tree.c (build_array_type_1): Revert earlier change.
+
 2013-01-02  Yufeng Zhang  <yufeng.zhang@arm.com>
 
        * config/aarch64/aarch64-cores.def: Add entries for "cortex-a53" and
index a57051ebf5fa1587b7f44929b9bc714ada1a9865..626455696ce17d2e2ff35deac87e1aae51c4d5d6 100644 (file)
@@ -1,3 +1,10 @@
+2013-01-02  Jason Merrill  <jason@redhat.com>
+
+       PR c++/55032
+       PR c++/55245
+       * tree.c (build_cplus_array_type): Copy layout information
+       to main variant if necessary.
+
 2012-12-28  Kai Tietz  <ktietz@redhat.com>
 
        * rtti.c (LONGPTR_T): New helper-macro.
index c4302371b73910a351f5c28050ee099deb2639bd..c658582052b7b418140a4535bc69693ab46eddc0 100644 (file)
@@ -809,6 +809,15 @@ build_cplus_array_type (tree elt_type, tree index_type)
       t = build_array_type (elt_type, index_type);
     }
 
+  /* Push these needs up so that initialization takes place
+     more easily.  */
+  bool needs_ctor
+    = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
+  TYPE_NEEDS_CONSTRUCTING (t) = needs_ctor;
+  bool needs_dtor
+    = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
+  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = needs_dtor;
+
   /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the
      element type as well, so fix it up if needed.  */
   if (elt_type != TYPE_MAIN_VARIANT (elt_type))
@@ -818,6 +827,27 @@ build_cplus_array_type (tree elt_type, tree index_type)
 
       if (TYPE_MAIN_VARIANT (t) != m)
        {
+         if (COMPLETE_TYPE_P (t) && !COMPLETE_TYPE_P (m))
+           {
+             /* m was built before the element type was complete, so we
+                also need to copy the layout info from t.  */
+             tree size = TYPE_SIZE (t);
+             tree size_unit = TYPE_SIZE_UNIT (t);
+             unsigned int align = TYPE_ALIGN (t);
+             unsigned int user_align = TYPE_USER_ALIGN (t);
+             enum machine_mode mode = TYPE_MODE (t);
+             for (tree var = m; var; var = TYPE_NEXT_VARIANT (var))
+               {
+                 TYPE_SIZE (var) = size;
+                 TYPE_SIZE_UNIT (var) = size_unit;
+                 TYPE_ALIGN (var) = align;
+                 TYPE_USER_ALIGN (var) = user_align;
+                 SET_TYPE_MODE (var, mode);
+                 TYPE_NEEDS_CONSTRUCTING (var) = needs_ctor;
+                 TYPE_HAS_NONTRIVIAL_DESTRUCTOR (var) = needs_dtor;
+               }
+           }
+
          TYPE_MAIN_VARIANT (t) = m;
          TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m);
          TYPE_NEXT_VARIANT (m) = t;
@@ -828,12 +858,6 @@ build_cplus_array_type (tree elt_type, tree index_type)
   if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t)))
     TREE_NO_WARNING (TYPE_SIZE (t)) = 1;
 
-  /* Push these needs up so that initialization takes place
-     more easily.  */
-  TYPE_NEEDS_CONSTRUCTING (t)
-    = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type));
-  TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t)
-    = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type));
   return t;
 }
 
diff --git a/gcc/testsuite/g++.dg/init/array33.C b/gcc/testsuite/g++.dg/init/array33.C
new file mode 100644 (file)
index 0000000..4440d3d
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/55804
+// { dg-do run }
+
+int t = 0;
+template <typename> struct vector {
+  vector() { t++; }
+};
+
+typedef vector<int> Arrays[1];
+class C
+{
+    vector<int> v_;
+    void Foo(const Arrays &);
+};
+Arrays a;
+
+int main(void)
+{
+  if (t!=1)
+    __builtin_abort ();
+  return 0;
+}
index 429db49e1a8c68b4528722d8e42a00e1ea5f59c4..7cacb2a0d64c072457694eb19abd080c9a4ebe09 100644 (file)
@@ -7505,12 +7505,7 @@ 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)