This commit is contained in:
2025-10-25 03:02:53 +03:00
commit 043225d523
3416 changed files with 681196 additions and 0 deletions

315
cppdraft/class/prop.md Normal file
View File

@@ -0,0 +1,315 @@
[class.prop]
# 11 Classes [[class]](./#class)
## 11.2 Properties of classes [class.prop]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L178)
A [*trivially copyable class*](#def:class,trivially_copyable "11.2Properties of classes[class.prop]") is a class:
- [(1.1)](#1.1)
that has at least one eligible
copy constructor, move constructor,
copy assignment operator, or
move assignment operator ([[special]](special "11.4.4Special member functions"), [[class.copy.ctor]](class.copy.ctor "11.4.5.3Copy/move constructors"), [[class.copy.assign]](class.copy.assign "11.4.6Copy/move assignment operator")),
- [(1.2)](#1.2)
where each eligible copy constructor, move constructor, copy assignment operator,
and move assignment operator is trivial, and
- [(1.3)](#1.3)
that has a trivial, non-deleted destructor ([[class.dtor]](class.dtor "11.4.7Destructors"))[.](#1.sentence-1)
[2](#2)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L190)
A class C is [*default-movable*](#def:default-movable "11.2Properties of classes[class.prop]") if
- [(2.1)](#2.1)
overload resolution for direct-initializing an object of type C from an xvalue of type C selects a constructor that is a direct member
of C and is neither user-provided nor deleted,
- [(2.2)](#2.2)
overload resolution for assigning to an lvalue of type C from an
xvalue of type C selects an assignment operator function that is a
direct member of C and is neither user-provided nor deleted, and
- [(2.3)](#2.3)
C has a destructor that is neither user-provided nor deleted.
[3](#3)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L205)
A class is [*eligible for trivial relocation*](#def:eligible_for_trivial_relocation "11.2Properties of classes[class.prop]") unless it
- [(3.1)](#3.1)
has any virtual base classes,
- [(3.2)](#3.2)
has a base class that is not a trivially relocatable class,
- [(3.3)](#3.3)
has a non-static data member of an object type that is not of a
trivially relocatable type, or
- [(3.4)](#3.4)
has a deleted destructor,
except that it is implementation-defined
whether an otherwise-eligible union having one or more subobjects of
polymorphic class type is eligible for trivial relocation[.](#3.sentence-1)
[4](#4)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L220)
A class C is a [*trivially relocatable class*](#def:class,trivially_relocatable "11.2Properties of classes[class.prop]") if it is eligible for trivial relocation and
- [(4.1)](#4.1)
has the trivially_relocatable_if_eligible [*class-property-specifier*](class.pre#nt:class-property-specifier "11.1Preamble[class.pre]"),
- [(4.2)](#4.2)
is a union with no user-declared special member functions, or
- [(4.3)](#4.3)
is default-movable[.](#4.sentence-1)
[5](#5)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L229)
[*Note [1](#note-1)*:
A class with const-qualified or reference non-static data members can be
trivially relocatable[.](#5.sentence-1)
— *end note*]
[6](#6)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L235)
A class C is [*eligible for replacement*](#def:eligible_for_replacement "11.2Properties of classes[class.prop]") unless
- [(6.1)](#6.1)
it has a base class that is not a replaceable class,
- [(6.2)](#6.2)
it has a non-static data member that is not of a replaceable type,
- [(6.3)](#6.3)
overload resolution fails or selects a deleted constructor when
direct-initializing an object of type C from an xvalue of typeC ([[dcl.init.general]](dcl.init.general "9.5.1General")),
- [(6.4)](#6.4)
overload resolution fails or selects a deleted assignment operator
function when assigning to an lvalue of type C from an xvalue of typeC ([[expr.assign]](expr.assign "7.6.19Assignment and compound assignment operators"), [[over.assign]](over.assign "12.4.3.2Simple assignment")), or
- [(6.5)](#6.5)
it has a deleted destructor[.](#6.sentence-1)
[7](#7)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L252)
A class C is a [*replaceable class*](#def:class,replaceable "11.2Properties of classes[class.prop]") if it is
eligible for replacement and
- [(7.1)](#7.1)
has the replaceable_if_eligible [*class-property-specifier*](class.pre#nt:class-property-specifier "11.1Preamble[class.pre]"),
- [(7.2)](#7.2)
is a union with no user-declared special member functions, or
- [(7.3)](#7.3)
is default-movable[.](#7.sentence-1)
[8](#8)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L261)
[*Note [2](#note-2)*:
Accessibility of the special member functions is not considered when
establishing trivial relocatability or replaceability[.](#8.sentence-1)
— *end note*]
[9](#9)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L267)
[*Note [3](#note-3)*:
Not all trivially copyable classes are trivially relocatable or replaceable[.](#9.sentence-1)
— *end note*]
[10](#10)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L272)
A class S is a [*standard-layout class*](#def:class,standard-layout "11.2Properties of classes[class.prop]") if it:
- [(10.1)](#10.1)
has no non-static data members of type non-standard-layout class
(or array of such types) or reference,
- [(10.2)](#10.2)
has no [virtual functions](class.virtual "11.7.3Virtual functions[class.virtual]") and no[virtual base classes](class.mi "11.7.2Multiple base classes[class.mi]"),
- [(10.3)](#10.3)
has the same [access control](class.access "11.8Member access control[class.access]") for all non-static data members,
- [(10.4)](#10.4)
has no non-standard-layout base classes,
- [(10.5)](#10.5)
has at most one base class subobject of any given type,
- [(10.6)](#10.6)
has all non-static data members and bit-fields in the class and
its base classes first declared in the same class, and
- [(10.7)](#10.7)
has no element of the set M(S) of types
as a base class,
where for any type X, M(X) is defined as follows[.](#10.sentence-1)[88](#footnote-88 "This ensures that two subobjects that have the same class type and that belong to the same most derived object are not allocated at the same address ([expr.eq]).")
[*Note [4](#note-4)*:
M(X) is the set of the types of all non-base-class subobjects
that can be at a zero offset in X[.](#10.7.sentence-2)
— *end note*]
* [(10.7.1)](#10.7.1)
If X is a non-union class type with no non-static data members,
the set M(X) is empty[.](#10.7.1.sentence-1)
* [(10.7.2)](#10.7.2)
If X is a non-union class type with a non-static data
member of type X0 that is either of zero size or
is the first non-static data member of X (where said member may be an anonymous union),
the set M(X) consists of X0 and the elements ofM(X0)[.](#10.7.2.sentence-1)
* [(10.7.3)](#10.7.3)
If X is a union type, the set M(X) is
the union of all M(Ui) and the set containing all Ui,
where each Ui is the type of the ith non-static data member
of X[.](#10.7.3.sentence-1)
* [(10.7.4)](#10.7.4)
If X is an array type with element type Xe,
the set M(X) consists of Xe and the elements of M(Xe)[.](#10.7.4.sentence-1)
* [(10.7.5)](#10.7.5)
If X is a non-class, non-array type, the set M(X) is empty[.](#10.7.5.sentence-1)
[11](#11)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L330)
[*Example [1](#example-1)*: struct B { int i; }; // standard-layout classstruct C : B { }; // standard-layout classstruct D : C { }; // standard-layout classstruct E : D { char : 4; }; // not a standard-layout classstruct Q {};struct S : Q { };struct T : Q { };struct U : S, T { }; // not a standard-layout class — *end example*]
[12](#12)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L345)
A [*standard-layout struct*](#def:struct,standard-layout "11.2Properties of classes[class.prop]") is a standard-layout class
defined with the [*class-key*](class.pre#nt:class-key "11.1Preamble[class.pre]") struct or the[*class-key*](class.pre#nt:class-key "11.1Preamble[class.pre]") class[.](#12.sentence-1)
A [*standard-layout union*](#def:union,standard-layout "11.2Properties of classes[class.prop]") is a standard-layout class
defined with the[*class-key*](class.pre#nt:class-key "11.1Preamble[class.pre]") union[.](#12.sentence-2)
[13](#13)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L353)
[*Note [5](#note-5)*:
Standard-layout classes are useful for communicating with
code written in other programming languages[.](#13.sentence-1)
Their layout is specified
in [[class.mem.general]](class.mem.general "11.4.1General") and [[expr.rel]](expr.rel "7.6.9Relational operators")[.](#13.sentence-2)
— *end note*]
[14](#14)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L360)
[*Example [2](#example-2)*: struct N { // neither trivially copyable nor standard-layoutint i; int j; virtual ~N();};
struct T { // trivially copyable but not standard-layoutint i;private:int j;};
struct SL { // standard-layout but not trivially copyableint i; int j; ~SL();};
struct POD { // both trivially copyable and standard-layoutint i; int j;}; — *end example*]
[15](#15)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L388)
[*Note [6](#note-6)*:
Aggregates of class type are described in [[dcl.init.aggr]](dcl.init.aggr "9.5.2Aggregates")[.](#15.sentence-1)
— *end note*]
[16](#16)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/classes.tex#L393)
A class S is an [*implicit-lifetime class*](#def:class,implicit-lifetime "11.2Properties of classes[class.prop]") if
- [(16.1)](#16.1)
it is an aggregate whose destructor is not user-provided or
- [(16.2)](#16.2)
it has at least one trivial eligible constructor and
a trivial, non-deleted destructor[.](#16.sentence-1)
[88)](#footnote-88)[88)](#footnoteref-88)
This ensures that two subobjects that have the same class type and that
belong to the same most derived object are not allocated at the same
address ([[expr.eq]](expr.eq "7.6.10Equality operators"))[.](#footnote-88.sentence-1)