This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: copy-assignment of array type with trivial ctor


On May 18, 2002, "Brian R. Gaeke" <brg@sartre.dgate.ORG> wrote:

>> This patch fixes the problem.  If anyone could code up a testcase
>> based on the description above, so that we avoid any risks by basing
>> our test on the testcase I got from this customer, I'd be forever
>> grateful.  It could be a link test, should the copy assignment
>> operator not be defined, or it could test for run-time side-effects of
>> the copy assignment operator.  Thanks in advance,

> A testcase is attached.

Thanks, here's my original patch (still unreviewed; hint, hint :-)
along with the testcase you've proposed, now in patch format, with
formatting changes so that it fits the coding standards better (not
that this is too important for the testsuite, but still...).  OK to
install?

Now...  Could I perhaps convince you to contribute a testcase for this
other patch? :-)
<URL:http://gcc.gnu.org/ml/gcc-patches/2002-05/msg01271.html>

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>
	* init.c (build_vec_init): Don't try trivial construction in copy
	assignment.

2002-05-19  Alexandre Oliva  <aoliva@redhat.com>

Index: gcc/cp/init.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/init.c,v
retrieving revision 1.279
diff -u -p -r1.279 init.c
--- gcc/cp/init.c 19 May 2002 05:15:11 -0000 1.279
+++ gcc/cp/init.c 19 May 2002 05:26:20 -0000
@@ -2777,6 +2777,7 @@ build_vec_init (base, init, from_array)
     init = digest_init (atype, init, 0);
       
   if (init && !TYPE_NEEDS_CONSTRUCTING (type)
+      && from_array != 2
       && ((TREE_CODE (init) == CONSTRUCTOR
 	   /* Don't do this if the CONSTRUCTOR might contain something
 	      that might throw and require us to clean up.  */
Index: gcc/testsuite/ChangeLog
from  Brian R. Gaeke  <brg@dgate.ORG>

	* g++.dg/other/copy2.C: New test.

Index: gcc/testsuite/g++.dg/other/copy2.C
===================================================================
RCS file: gcc/testsuite/g++.dg/other/copy2.C
diff -N gcc/testsuite/g++.dg/other/copy2.C
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gcc/testsuite/g++.dg/other/copy2.C 19 May 2002 05:26:26 -0000
@@ -0,0 +1,32 @@
+// { dg-do run }
+
+// Test that A's copy assignment method is called when B's instance
+// member array of A is assigned.
+
+// Contributed by Brian Gaeke, public domain.
+int status = 1;
+
+class A
+{
+public:
+  int i;
+  A &operator =(const A &i)
+  {
+    status = 0;
+  }
+};
+
+class B
+{
+public:
+  A arr[10];
+};
+
+int main (int argc, char **argv)
+{
+  B b;
+  b.arr[0].i = 15;
+  B a;
+  a = b; // trigger copy assignment
+  return status;
+}

-- 
Alexandre Oliva   Enjoy Guarana', see http://www.ic.unicamp.br/~oliva/
Red Hat GCC Developer                  aoliva@{cygnus.com, redhat.com}
CS PhD student at IC-Unicamp        oliva@{lsd.ic.unicamp.br, gnu.org}
Free Software Evangelist                Professional serial bug killer

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]