From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 308843857817; Wed, 8 Sep 2021 23:30:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 308843857817 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8974] c++: Fix docs on assignment of virtual bases [PR60318] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: cb5690b8d2ce84fb943535bea0d587863cf57753 X-Git-Newrev: d7b2e9bd1a3cdb502bfd837d56ef809817ef0db7 Message-Id: <20210908233013.308843857817@sourceware.org> Date: Wed, 8 Sep 2021 23:30:13 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 08 Sep 2021 23:30:13 -0000 https://gcc.gnu.org/g:d7b2e9bd1a3cdb502bfd837d56ef809817ef0db7 commit r11-8974-gd7b2e9bd1a3cdb502bfd837d56ef809817ef0db7 Author: Jonathan Wakely Date: Tue Aug 31 09:46:41 2021 +0100 c++: Fix docs on assignment of virtual bases [PR60318] The description of behaviour is incorrect, the virtual base gets assigned before entering the bodies of A::operator= and B::operator=, not after. The example is also ill-formed (passing a string literal to char*) and undefined (missing return from Base::operator=). Signed-off-by: Jonathan Wakely gcc/ChangeLog: PR c++/60318 * doc/trouble.texi (Copy Assignment): Fix description of behaviour and fix code in example. (cherry picked from commit 3c64582372cf445eabc4f9e99def7e33fb0270ee) Diff: --- gcc/doc/trouble.texi | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/doc/trouble.texi b/gcc/doc/trouble.texi index 40c51ae21cb..8b34be4aa63 100644 --- a/gcc/doc/trouble.texi +++ b/gcc/doc/trouble.texi @@ -865,10 +865,11 @@ objects behave unspecified when being assigned. For example: @smallexample struct Base@{ char *name; - Base(char *n) : name(strdup(n))@{@} + Base(const char *n) : name(strdup(n))@{@} Base& operator= (const Base& other)@{ free (name); name = strdup (other.name); + return *this; @} @}; @@ -901,8 +902,8 @@ inside @samp{func} in the example). G++ implements the ``intuitive'' algorithm for copy-assignment: assign all direct bases, then assign all members. In that algorithm, the virtual base subobject can be encountered more than once. In the example, copying -proceeds in the following order: @samp{val}, @samp{name} (via -@code{strdup}), @samp{bval}, and @samp{name} again. +proceeds in the following order: @samp{name} (via @code{strdup}), +@samp{val}, @samp{name} again, and @samp{bval}. If application code relies on copy-assignment, a user-defined copy-assignment operator removes any uncertainties. With such an