+2015-06-24 Jason Merrill <jason@redhat.com>
+
+ PR c++/66501
+ * init.c (vec_copy_assign_is_trivial): New.
+ (build_vec_init): Use it.
+
2015-06-23 Jason Merrill <jason@redhat.com>
PR c++/65879
return decl;
}
+/* Subroutine of build_vec_init. Returns true if assigning to an array of
+ INNER_ELT_TYPE from INIT is trivial. */
+
+static bool
+vec_copy_assign_is_trivial (tree inner_elt_type, tree init)
+{
+ if (!CLASS_TYPE_P (inner_elt_type))
+ return true;
+ if (cxx_dialect >= cxx11
+ && !real_lvalue_p (init)
+ && type_has_move_assign (inner_elt_type))
+ return !TYPE_HAS_COMPLEX_MOVE_ASSIGN (inner_elt_type);
+ return TYPE_HAS_TRIVIAL_COPY_ASSIGN (inner_elt_type);
+}
+
/* `build_vec_init' returns tree structure that performs
initialization of a vector of aggregate types.
&& TREE_CODE (atype) == ARRAY_TYPE
&& TREE_CONSTANT (maxindex)
&& (from_array == 2
- ? (!CLASS_TYPE_P (inner_elt_type)
- || !TYPE_HAS_COMPLEX_COPY_ASSIGN (inner_elt_type))
+ ? vec_copy_assign_is_trivial (inner_elt_type, init)
: !TYPE_NEEDS_CONSTRUCTING (type))
&& ((TREE_CODE (init) == CONSTRUCTOR
/* Don't do this if the CONSTRUCTOR might contain something
--- /dev/null
+// PR c++/66501
+// { dg-do run { target c++11 } }
+
+int total_size;
+
+struct Object
+{
+ int size = 0;
+
+ Object () = default;
+
+ ~Object () {
+ total_size -= size;
+ }
+
+ Object (const Object &) = delete;
+ Object & operator= (const Object &) = delete;
+
+ Object (Object && b) {
+ size = b.size;
+ b.size = 0;
+ }
+
+ Object & operator= (Object && b) {
+ if (this != & b) {
+ total_size -= size;
+ size = b.size;
+ b.size = 0;
+ }
+ return * this;
+ }
+
+ void grow () {
+ size ++;
+ total_size ++;
+ }
+};
+
+struct Container {
+ Object objects[2];
+};
+
+int main (void)
+{
+ Container container;
+
+ // grow some objects in the container
+ for (auto & object : container.objects)
+ object.grow ();
+
+ // now empty it
+ container = Container ();
+
+ return total_size;
+}