public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3423] c++: Fix docs on assignment of virtual bases [PR60318]
@ 2021-09-08 21:34 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2021-09-08 21:34 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:3c64582372cf445eabc4f9e99def7e33fb0270ee

commit r12-3423-g3c64582372cf445eabc4f9e99def7e33fb0270ee
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.

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


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-09-08 21:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08 21:34 [gcc r12-3423] c++: Fix docs on assignment of virtual bases [PR60318] Jonathan Wakely

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).