From 82ba818ff456bcd6d56a06226e3f27e98fbb55c3 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Thu, 14 Aug 2025 22:58:58 -0500 Subject: removing all downloaded devdocs files --- devdocs/gcc~13/copy-assignment.html | 34 ---------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 devdocs/gcc~13/copy-assignment.html (limited to 'devdocs/gcc~13/copy-assignment.html') diff --git a/devdocs/gcc~13/copy-assignment.html b/devdocs/gcc~13/copy-assignment.html deleted file mode 100644 index 540d6119..00000000 --- a/devdocs/gcc~13/copy-assignment.html +++ /dev/null @@ -1,34 +0,0 @@ -

14.7.4 Implicit Copy-Assignment for Virtual Bases

When a base class is virtual, only one subobject of the base class belongs to each full object. Also, the constructors and destructors are invoked only once, and called from the most-derived class. However, such objects behave unspecified when being assigned. For example:

struct Base{
-  char *name;
-  Base(const char *n) : name(strdup(n)){}
-  Base& operator= (const Base& other){
-   free (name);
-   name = strdup (other.name);
-   return *this;
-  }
-};
-
-struct A:virtual Base{
-  int val;
-  A():Base("A"){}
-};
-
-struct B:virtual Base{
-  int bval;
-  B():Base("B"){}
-};
-
-struct Derived:public A, public B{
-  Derived():Base("Derived"){}
-};
-
-void func(Derived &d1, Derived &d2)
-{
-  d1 = d2;
-}
-

The C++ standard specifies that ‘Base::Base’ is only called once when constructing or copy-constructing a Derived object. It is unspecified whether ‘Base::operator=’ is called more than once when the implicit copy-assignment for Derived objects is invoked (as it is inside ‘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: ‘name’ (via strdup), ‘val’, ‘name’ again, and ‘bval’.

If application code relies on copy-assignment, a user-defined copy-assignment operator removes any uncertainties. With such an operator, the application can define whether and how the virtual base subobject is assigned.

-

- © Free Software Foundation
Licensed under the GNU Free Documentation License, Version 1.3.
- https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Copy-Assignment.html -

-
-- cgit v1.2.3