]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c++/13009 (Implicitly-defined assignment operator writes to wrong...
authorGabriel Dos Reis <gdr@integrable-solutions.net>
Wed, 21 Jan 2004 05:04:05 +0000 (05:04 +0000)
committerGabriel Dos Reis <gdr@gcc.gnu.org>
Wed, 21 Jan 2004 05:04:05 +0000 (05:04 +0000)
        Backport from mainline
        2003-12-28  Mark Mitchell  <mark@codesourcery.com>

        PR c++/13009
        * call.c (build_special_member_call): Do not assume that we
        have a
        pointer to the complete object in an assignment operator.

From-SVN: r76257

gcc/cp/ChangeLog
gcc/cp/call.c

index 04fe29e32f72d430e6d6c64f8be5e85144acbc96..2d0c3261a6bd9e1c747611b523cd08750548c3e8 100644 (file)
@@ -1,3 +1,12 @@
+2004-01-21  Gabriel Dos Reis  <gdr@integrable-solutions.net>
+
+       Backport from mainline
+       2003-12-28  Mark Mitchell  <mark@codesourcery.com>
+
+       PR c++/13009
+       * call.c (build_special_member_call): Do not assume that we have a
+        pointer to the complete object in an assignment operator.
+       
 2004-01-20  Kriang Lerdsuwanakij  <lerdsuwa@users.sourceforge.net>
 
        PR c++/13289
index 1a1a493774b1dfa41b3393854f96bf799ac2e71a..30636ab7bc052f81b0ec3fded920b00291970b18 100644 (file)
@@ -4878,14 +4878,23 @@ build_special_member_call (tree instance, tree name, tree args,
          || name == deleting_dtor_identifier)
        my_friendly_assert (args == NULL_TREE, 20020712);
 
-      /* We must perform the conversion here so that we do not
-        subsequently check to see whether BINFO is an accessible
-        base.  (It is OK for a constructor to call a constructor in
-        an inaccessible base as long as the constructor being called
-        is accessible.)  */
+      /* Convert to the base class, if necessary.  */
       if (!same_type_ignoring_top_level_qualifiers_p 
          (TREE_TYPE (instance), BINFO_TYPE (binfo)))
-       instance = convert_to_base_statically (instance, binfo);
+       {
+         if (name != ansi_assopname (NOP_EXPR))
+           /* For constructors and destructors, either the base is
+              non-virtual, or it is virtual but we are doing the
+              conversion from a constructor or destructor for the
+              complete object.  In either case, we can convert
+              statically.  */
+           instance = convert_to_base_statically (instance, binfo);
+         else
+           /* However, for assignment operators, we must convert
+              dynamically if the base is virtual.  */
+           instance = build_base_path (PLUS_EXPR, instance,
+                                       binfo, /*nonnull=*/1);
+       }
     }
   
   my_friendly_assert (instance != NULL_TREE, 20020712);