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]

copy-assignment of array type with trivial ctor


A customer has reported a problem in our C++ compiler.  Being unsure
about the copyright status of the testcase I've received, I'm taking
the safe path and not including it in the patch, so I'll describe the
problem here.

Given a class say A with a trivial ctor and dtor, but with a
user-defined copy assignment operator, and a class B with a non-static
data member of type array of A, the compiler-generated copy assignment
operator of class B (as well as the GNU extension of copying arrays)
will not use the copy assignment operator of A.  Instead, it would
apply trivial copy-construction (memcpy) to the elements of the
assigned-to array.

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,

Ok to install?  Or should I instead change the `|| from_array' that
causes the test to succeed even though we didn't get a CONSTRUCTOR to
`|| from_array == 1'?

Index: gcc/cp/ChangeLog
from  Alexandre Oliva  <aoliva@redhat.com>

	* init.c (build_vec_init): Don't try trivial construction in copy
	assignment.

Index: gcc/cp/init.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/init.c,v
retrieving revision 1.278
diff -u -p -r1.278 init.c
--- gcc/cp/init.c 14 May 2002 17:20:47 -0000 1.278
+++ gcc/cp/init.c 16 May 2002 04:50:19 -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.  */

-- 
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]