public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r9-9715] c++: Fix docs on assignment of virtual bases [PR60318]
Date: Wed,  8 Sep 2021 23:34:06 +0000 (GMT)	[thread overview]
Message-ID: <20210908233406.1B9323857817@sourceware.org> (raw)

https://gcc.gnu.org/g:03b8e26897fbddec10a703cf518280af675e6458

commit r9-9715-g03b8e26897fbddec10a703cf518280af675e6458
Author: Jonathan Wakely <jwakely@redhat.com>
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 <jwakely@redhat.com>
    
    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 693912ea355..aaee8fba6bb 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


                 reply	other threads:[~2021-09-08 23:34 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210908233406.1B9323857817@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).