- tmp/tmpfp9oq78c/{from.md → to.md} +355 -277
tmp/tmpfp9oq78c/{from.md → to.md}
RENAMED
|
@@ -25,12 +25,12 @@ A *name* is a use of an *identifier* ([[lex.name]]),
|
|
| 25 |
Every name that denotes an entity is introduced by a *declaration*.
|
| 26 |
Every name that denotes a label is introduced either by a `goto`
|
| 27 |
statement ([[stmt.goto]]) or a *labeled-statement* ([[stmt.label]]).
|
| 28 |
|
| 29 |
A *variable* is introduced by the declaration of a reference other than
|
| 30 |
-
a non-static data member or of an object. The variable’s name
|
| 31 |
-
the reference or object.
|
| 32 |
|
| 33 |
Some names denote types or templates. In general, whenever a name is
|
| 34 |
encountered it is necessary to determine whether that name denotes one
|
| 35 |
of these entities before continuing to parse the program that contains
|
| 36 |
it. The process that determines this is called *name lookup* (
|
|
@@ -39,12 +39,12 @@ it. The process that determines this is called *name lookup* (
|
|
| 39 |
Two names are *the same* if
|
| 40 |
|
| 41 |
- they are *identifier*s composed of the same character sequence, or
|
| 42 |
- they are *operator-function-id*s formed with the same operator, or
|
| 43 |
- they are *conversion-function-id*s formed with the same type, or
|
| 44 |
-
- they are *template-id*s that refer to the same class
|
| 45 |
-
[[temp.type]]), or
|
| 46 |
- they are the names of literal operators ([[over.literal]]) formed
|
| 47 |
with the same literal suffix identifier.
|
| 48 |
|
| 49 |
A name used in more than one translation unit can potentially refer to
|
| 50 |
the same entity in these translation units depending on the linkage (
|
|
@@ -157,47 +157,81 @@ an incomplete type ([[basic.types]]).
|
|
| 157 |
|
| 158 |
No translation unit shall contain more than one definition of any
|
| 159 |
variable, function, class type, enumeration type, or template.
|
| 160 |
|
| 161 |
An expression is *potentially evaluated* unless it is an unevaluated
|
| 162 |
-
operand (Clause [[expr]]) or a subexpression thereof.
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
is odr-used by
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
Every program shall contain exactly one definition of every non-inline
|
| 201 |
function or variable that is odr-used in that program; no diagnostic
|
| 202 |
required. The definition can appear explicitly in the program, it can be
|
| 203 |
found in the standard or a user-defined library, or (when appropriate)
|
|
@@ -228,12 +262,12 @@ complete class types are required. A class type `T` must be complete if:
|
|
| 228 |
object of type `T` ([[conv.lval]]), or
|
| 229 |
- an expression is converted (either implicitly or explicitly) to type
|
| 230 |
`T` (Clause [[conv]], [[expr.type.conv]], [[expr.dynamic.cast]],
|
| 231 |
[[expr.static.cast]], [[expr.cast]]), or
|
| 232 |
- an expression that is not a null pointer constant, and has type other
|
| 233 |
-
than `void*`, is converted to the type pointer to `T` or
|
| 234 |
-
`T` using
|
| 235 |
`dynamic_cast` ([[expr.dynamic.cast]]) or a `static_cast` (
|
| 236 |
[[expr.static.cast]]), or
|
| 237 |
- a class member access operator is applied to an expression of type
|
| 238 |
`T` ([[expr.ref]]), or
|
| 239 |
- the `typeid` operator ([[expr.typeid]]) or the `sizeof` operator (
|
|
@@ -265,15 +299,15 @@ unit, then
|
|
| 265 |
- in each definition of `D`, corresponding names, looked up according
|
| 266 |
to [[basic.lookup]], shall refer to an entity defined within the
|
| 267 |
definition of `D`, or shall refer to the same entity, after overload
|
| 268 |
resolution ([[over.match]]) and after matching of partial template
|
| 269 |
specialization ([[temp.over]]), except that a name can refer to a
|
| 270 |
-
`const` object with internal or no linkage if the object
|
| 271 |
-
literal type in all definitions of `D`, and the object is
|
| 272 |
-
with a constant expression ([[expr.const]]), and the
|
| 273 |
-
|
| 274 |
-
|
| 275 |
- in each definition of `D`, corresponding entities shall have the same
|
| 276 |
language linkage; and
|
| 277 |
- in each definition of `D`, the overloaded operators referred to, the
|
| 278 |
implicit calls to conversion functions, constructors, operator new
|
| 279 |
functions and operator delete functions, shall refer to the same
|
|
@@ -313,12 +347,12 @@ unit, then
|
|
| 313 |
If `D` is a template and is defined in more than one translation unit,
|
| 314 |
then the preceding requirements shall apply both to names from the
|
| 315 |
template’s enclosing scope used in the template definition (
|
| 316 |
[[temp.nondep]]), and also to dependent names at the point of
|
| 317 |
instantiation ([[temp.dep]]). If the definitions of `D` satisfy all
|
| 318 |
-
these requirements, then the
|
| 319 |
-
|
| 320 |
requirements, then the behavior is undefined.
|
| 321 |
|
| 322 |
## Scope <a id="basic.scope">[[basic.scope]]</a>
|
| 323 |
|
| 324 |
### Declarative regions and scopes <a id="basic.scope.declarative">[[basic.scope.declarative]]</a>
|
|
@@ -392,12 +426,12 @@ The name lookup rules are summarized in [[basic.lookup]].
|
|
| 392 |
The *point of declaration* for a name is immediately after its complete
|
| 393 |
declarator (Clause [[dcl.decl]]) and before its *initializer* (if any),
|
| 394 |
except as noted below.
|
| 395 |
|
| 396 |
``` cpp
|
| 397 |
-
|
| 398 |
-
{
|
| 399 |
```
|
| 400 |
|
| 401 |
Here the second `x` is initialized with its own (indeterminate) value.
|
| 402 |
|
| 403 |
a name from an outer scope remains visible up to the point of
|
|
@@ -417,10 +451,14 @@ The point of declaration for an enumeration is immediately after the
|
|
| 417 |
*identifier* (if any) in either its *enum-specifier* ([[dcl.enum]]) or
|
| 418 |
its first *opaque-enum-declaration* ([[dcl.enum]]), whichever comes
|
| 419 |
first. The point of declaration of an alias or alias template
|
| 420 |
immediately follows the *type-id* to which the alias refers.
|
| 421 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
The point of declaration for an enumerator is immediately after its
|
| 423 |
*enumerator-definition*.
|
| 424 |
|
| 425 |
``` cpp
|
| 426 |
const int x = 12;
|
|
@@ -492,11 +530,11 @@ block scope and variable declarations with the `extern` specifier at
|
|
| 492 |
block scope refer to declarations that are members of an enclosing
|
| 493 |
namespace, but they do not introduce new names into that scope.
|
| 494 |
|
| 495 |
For point of instantiation of a template, see [[temp.point]].
|
| 496 |
|
| 497 |
-
### Block scope <a id="basic.scope.
|
| 498 |
|
| 499 |
A name declared in a block ([[stmt.block]]) is local to that block; it
|
| 500 |
has *block scope*. Its potential scope begins at its point of
|
| 501 |
declaration ([[basic.scope.pdecl]]) and ends at the end of its block. A
|
| 502 |
variable declared at block scope is a *local variable*.
|
|
@@ -588,12 +626,12 @@ namespace in a *using-directive;* see [[namespace.qual]].
|
|
| 588 |
The outermost declarative region of a translation unit is also a
|
| 589 |
namespace, called the *global namespace*. A name declared in the global
|
| 590 |
namespace has *global namespace scope* (also called *global scope*). The
|
| 591 |
potential scope of such a name begins at its point of declaration (
|
| 592 |
[[basic.scope.pdecl]]) and ends at the end of the translation unit that
|
| 593 |
-
is its declarative region.
|
| 594 |
-
be *global name*.
|
| 595 |
|
| 596 |
### Class scope <a id="basic.scope.class">[[basic.scope.class]]</a>
|
| 597 |
|
| 598 |
The following rules describe the scope of names declared in classes.
|
| 599 |
|
|
@@ -814,12 +852,13 @@ void A::N::f() {
|
|
| 814 |
// 4) global scope, before the definition of A::N::f
|
| 815 |
}
|
| 816 |
```
|
| 817 |
|
| 818 |
A name used in the definition of a class `X` outside of a member
|
| 819 |
-
function body
|
| 820 |
-
|
|
|
|
| 821 |
|
| 822 |
- before its use in class `X` or be a member of a base class of `X` (
|
| 823 |
[[class.member.lookup]]), or
|
| 824 |
- if `X` is a nested class of class `Y` ([[class.nest]]), before the
|
| 825 |
definition of `X` in `Y`, or shall be a member of a base class of `Y`
|
|
@@ -864,15 +903,16 @@ namespace scope are not considered; see [[namespace.memdef]].
|
|
| 864 |
names in a class definition. [[class.nest]] further describes the
|
| 865 |
restrictions on the use of names in nested class definitions.
|
| 866 |
[[class.local]] further describes the restrictions on the use of names
|
| 867 |
in local class definitions.
|
| 868 |
|
| 869 |
-
|
| 870 |
-
|
| 871 |
*brace-or-equal-initializer* of a non-static data member (
|
| 872 |
-
[[class.mem]])
|
| 873 |
-
|
|
|
|
| 874 |
|
| 875 |
- before its use in the block in which it is used or in an enclosing
|
| 876 |
block ([[stmt.block]]), or
|
| 877 |
- shall be a member of class `X` or be a member of a base class of `X` (
|
| 878 |
[[class.member.lookup]]), or
|
|
@@ -999,14 +1039,14 @@ The rules for name lookup in template definitions are described in
|
|
| 999 |
### Argument-dependent name lookup <a id="basic.lookup.argdep">[[basic.lookup.argdep]]</a>
|
| 1000 |
|
| 1001 |
When the *postfix-expression* in a function call ([[expr.call]]) is an
|
| 1002 |
*unqualified-id*, other namespaces not considered during the usual
|
| 1003 |
unqualified lookup ([[basic.lookup.unqual]]) may be searched, and in
|
| 1004 |
-
those namespaces, namespace-scope friend function
|
| 1005 |
-
[[class.friend]]) not otherwise visible may be found.
|
| 1006 |
-
modifications to the search depend on the types of the arguments
|
| 1007 |
-
for template template arguments, the namespace of the template
|
| 1008 |
argument).
|
| 1009 |
|
| 1010 |
``` cpp
|
| 1011 |
namespace N {
|
| 1012 |
struct S { };
|
|
@@ -1033,23 +1073,23 @@ way:
|
|
| 1033 |
- If `T` is a fundamental type, its associated sets of namespaces and
|
| 1034 |
classes are both empty.
|
| 1035 |
- If `T` is a class type (including unions), its associated classes are:
|
| 1036 |
the class itself; the class of which it is a member, if any; and its
|
| 1037 |
direct and indirect base classes. Its associated namespaces are the
|
| 1038 |
-
namespaces of
|
| 1039 |
if `T` is a class template specialization, its associated namespaces
|
| 1040 |
and classes also include: the namespaces and classes associated with
|
| 1041 |
the types of the template arguments provided for template type
|
| 1042 |
parameters (excluding template template parameters); the namespaces of
|
| 1043 |
which any template template arguments are members; and the classes of
|
| 1044 |
which any member templates used as template template arguments are
|
| 1045 |
members. Non-type template arguments do not contribute to the set of
|
| 1046 |
associated namespaces.
|
| 1047 |
- If `T` is an enumeration type, its associated namespace is the
|
| 1048 |
-
|
| 1049 |
-
associated class is the member’s class; else it has no
|
| 1050 |
-
class.
|
| 1051 |
- If `T` is a pointer to `U` or an array of `U`, its associated
|
| 1052 |
namespaces and classes are those associated with `U`.
|
| 1053 |
- If `T` is a function type, its associated namespaces and classes are
|
| 1054 |
those associated with the function parameter types and those
|
| 1055 |
associated with the return type.
|
|
@@ -1226,12 +1266,12 @@ lookup rule above are the following:
|
|
| 1226 |
the context in which the entire *postfix-expression* occurs.
|
| 1227 |
- the lookup for a name specified in a *using-declaration* (
|
| 1228 |
[[namespace.udecl]]) also finds class or enumeration names hidden
|
| 1229 |
within the same scope ([[basic.scope.hiding]]).
|
| 1230 |
|
| 1231 |
-
In a lookup in which
|
| 1232 |
-
|
| 1233 |
|
| 1234 |
- if the name specified after the *nested-name-specifier*, when looked
|
| 1235 |
up in `C`, is the injected-class-name of `C` (Clause [[class]]), or
|
| 1236 |
- in a *using-declaration* ([[namespace.udecl]]) that is a
|
| 1237 |
*member-declaration*, if the name specified after the
|
|
@@ -1567,16 +1607,15 @@ If the *id-expression* in a class member access ([[expr.ref]]) is an
|
|
| 1567 |
*unqualified-id*, and the type of the object expression is of a class
|
| 1568 |
type `C`, the *unqualified-id* is looked up in the scope of class `C`.
|
| 1569 |
For a pseudo-destructor call ([[expr.pseudo]]), the *unqualified-id* is
|
| 1570 |
looked up in the context of the complete *postfix-expression*.
|
| 1571 |
|
| 1572 |
-
If the *unqualified-id* is *
|
| 1573 |
-
|
| 1574 |
-
|
| 1575 |
-
|
| 1576 |
-
|
| 1577 |
-
`T`.
|
| 1578 |
|
| 1579 |
``` cpp
|
| 1580 |
struct A { };
|
| 1581 |
|
| 1582 |
struct B {
|
|
@@ -1662,13 +1701,13 @@ introduced by a declaration in another scope:
|
|
| 1662 |
A name having namespace scope ([[basic.scope.namespace]]) has internal
|
| 1663 |
linkage if it is the name of
|
| 1664 |
|
| 1665 |
- a variable, function or function template that is explicitly declared
|
| 1666 |
`static`; or,
|
| 1667 |
-
- a variable that is explicitly declared `const` or
|
| 1668 |
-
neither explicitly declared `extern` nor previously
|
| 1669 |
-
external linkage; or
|
| 1670 |
- a data member of an anonymous union.
|
| 1671 |
|
| 1672 |
An unnamed namespace or a namespace declared directly or indirectly
|
| 1673 |
within an unnamed namespace has internal linkage. All other namespaces
|
| 1674 |
have external linkage. A name having namespace scope that has not been
|
|
@@ -1743,18 +1782,18 @@ namespace X {
|
|
| 1743 |
|
| 1744 |
void q() { /* ... */ } // some other, unrelated q
|
| 1745 |
```
|
| 1746 |
|
| 1747 |
Names not covered by these rules have no linkage. Moreover, except as
|
| 1748 |
-
noted, a name declared at block scope ([[basic.scope.
|
| 1749 |
linkage. A type is said to have linkage if and only if:
|
| 1750 |
|
| 1751 |
- it is a class or enumeration type that is named (or has a name for
|
| 1752 |
linkage purposes ([[dcl.typedef]])) and the name has linkage; or
|
| 1753 |
- it is an unnamed class or enumeration member of a class with linkage;
|
| 1754 |
or
|
| 1755 |
-
- it is a specialization of a class template
|
| 1756 |
- it is a fundamental type ([[basic.fundamental]]); or
|
| 1757 |
- it is a compound type ([[basic.compound]]) other than a class or
|
| 1758 |
enumeration, compounded exclusively from types that have linkage; or
|
| 1759 |
- it is a cv-qualified ([[basic.type.qualifier]]) version of a type
|
| 1760 |
that has linkage.
|
|
@@ -1830,37 +1869,33 @@ function. In a freestanding environment, start-up and termination is
|
|
| 1830 |
constructors for objects of namespace scope with static storage
|
| 1831 |
duration; termination contains the execution of destructors for objects
|
| 1832 |
with static storage duration.
|
| 1833 |
|
| 1834 |
An implementation shall not predefine the `main` function. This function
|
| 1835 |
-
shall not be overloaded. It shall have a return type of type
|
| 1836 |
-
otherwise its type is *implementation-defined*.
|
| 1837 |
-
shall allow both
|
| 1838 |
|
| 1839 |
-
```
|
| 1840 |
-
|
| 1841 |
-
```
|
| 1842 |
|
| 1843 |
-
|
| 1844 |
-
|
| 1845 |
-
```
|
| 1846 |
-
|
| 1847 |
-
``
|
| 1848 |
-
|
| 1849 |
-
|
| 1850 |
-
|
| 1851 |
-
|
| 1852 |
-
`
|
| 1853 |
-
|
| 1854 |
-
be
|
| 1855 |
-
name used to invoke the program or `""`. The value of `argc` shall be
|
| 1856 |
-
non-negative. The value of `argv[argc]` shall be 0. It is recommended
|
| 1857 |
-
that any further (optional) parameters be added after `argv`.
|
| 1858 |
|
| 1859 |
The function `main` shall not be used within a program. The linkage (
|
| 1860 |
[[basic.link]]) of `main` is *implementation-defined*. A program that
|
| 1861 |
-
defines `main` as deleted or that declares `main` to be `inline
|
| 1862 |
`static`, or `constexpr` is ill-formed. The name `main` is not otherwise
|
| 1863 |
reserved. member functions, classes, and enumerations can be called
|
| 1864 |
`main`, as can entities in other namespaces.
|
| 1865 |
|
| 1866 |
Terminating the program without leaving the current block (e.g., by
|
|
@@ -1890,29 +1925,29 @@ initiation. Non-local variables with thread storage duration are
|
|
| 1890 |
initialized as a consequence of thread execution. Within each of these
|
| 1891 |
phases of initiation, initialization occurs as follows.
|
| 1892 |
|
| 1893 |
Variables with static storage duration ([[basic.stc.static]]) or thread
|
| 1894 |
storage duration ([[basic.stc.thread]]) shall be zero-initialized (
|
| 1895 |
-
[[dcl.init]]) before any other initialization takes place.
|
| 1896 |
-
|
| 1897 |
-
|
|
|
|
|
|
|
|
|
|
| 1898 |
|
| 1899 |
- if each full-expression (including implicit conversions) that appears
|
| 1900 |
in the initializer of a reference with static or thread storage
|
| 1901 |
duration is a constant expression ([[expr.const]]) and the reference
|
| 1902 |
is bound to an lvalue designating an object with static storage
|
| 1903 |
-
duration
|
| 1904 |
- if an object with static or thread storage duration is initialized by
|
| 1905 |
-
a constructor call, if the
|
| 1906 |
-
|
| 1907 |
-
conversions), and if, after function invocation substitution (
|
| 1908 |
-
[[dcl.constexpr]]), every constructor call and full-expression in the
|
| 1909 |
-
*mem-initializer*s and in the *brace-or-equal-initializer*s for
|
| 1910 |
-
non-static data members is a constant expression;
|
| 1911 |
- if an object with static or thread storage duration is not initialized
|
| 1912 |
-
by a constructor call and if
|
| 1913 |
-
initializer is a constant
|
|
|
|
| 1914 |
|
| 1915 |
Together, zero-initialization and constant initialization are called
|
| 1916 |
*static initialization*; all other initialization is *dynamic
|
| 1917 |
initialization*. Static initialization shall be performed before any
|
| 1918 |
dynamic initialization takes place. Dynamic initialization of a
|
|
@@ -1970,11 +2005,11 @@ double d1 = fd(); // may be initialized statically or dynamically to 1.0
|
|
| 1970 |
It is *implementation-defined* whether the dynamic initialization of a
|
| 1971 |
non-local variable with static storage duration is done before the first
|
| 1972 |
statement of `main`. If the initialization is deferred to some point in
|
| 1973 |
time after the first statement of `main`, it shall occur before the
|
| 1974 |
first odr-use ([[basic.def.odr]]) of any function or variable defined
|
| 1975 |
-
in the same translation unit as the variable to be initialized.[^
|
| 1976 |
|
| 1977 |
``` cpp
|
| 1978 |
// - File 1 -
|
| 1979 |
#include "a.h"
|
| 1980 |
#include "b.h"
|
|
@@ -2175,12 +2210,14 @@ implicitly declared in global scope in each translation unit of a
|
|
| 2175 |
program.
|
| 2176 |
|
| 2177 |
``` cpp
|
| 2178 |
void* operator new(std::size_t);
|
| 2179 |
void* operator new[](std::size_t);
|
| 2180 |
-
void operator delete(void*);
|
| 2181 |
-
void operator delete[](void*);
|
|
|
|
|
|
|
| 2182 |
```
|
| 2183 |
|
| 2184 |
These implicit declarations introduce only the function names `operator`
|
| 2185 |
`new`, `operator` `new[]`, `operator` `delete`, and `operator`
|
| 2186 |
`delete[]`. The implicit declarations do not introduce the names `std`,
|
|
@@ -2226,64 +2263,70 @@ storage allocated (until the storage is explicitly deallocated by a call
|
|
| 2226 |
to a corresponding deallocation function). Even if the size of the space
|
| 2227 |
requested is zero, the request can fail. If the request succeeds, the
|
| 2228 |
value returned shall be a non-null pointer value ([[conv.ptr]]) `p0`
|
| 2229 |
different from any previously returned value `p1`, unless that value
|
| 2230 |
`p1` was subsequently passed to an `operator` `delete`. The effect of
|
| 2231 |
-
|
| 2232 |
-
undefined.[^
|
| 2233 |
|
| 2234 |
An allocation function that fails to allocate storage can invoke the
|
| 2235 |
currently installed new-handler function ([[new.handler]]), if any. A
|
| 2236 |
program-supplied allocation function can obtain the address of the
|
| 2237 |
currently installed `new_handler` using the `std::get_new_handler`
|
| 2238 |
function ([[set.new.handler]]). If an allocation function declared with
|
| 2239 |
a non-throwing *exception-specification* ([[except.spec]]) fails to
|
| 2240 |
allocate storage, it shall return a null pointer. Any other allocation
|
| 2241 |
function that fails to allocate storage shall indicate failure only by
|
| 2242 |
-
throwing an exception of a type that would match a
|
| 2243 |
-
[[except.handle]]) of type `std::bad_alloc` ([[bad.alloc]]).
|
| 2244 |
|
| 2245 |
A global allocation function is only called as the result of a new
|
| 2246 |
expression ([[expr.new]]), or called directly using the function call
|
| 2247 |
syntax ([[expr.call]]), or called indirectly through calls to the
|
| 2248 |
functions in the C++standard library. In particular, a global allocation
|
| 2249 |
function is not called to allocate storage for objects with static
|
| 2250 |
storage duration ([[basic.stc.static]]), for objects or references with
|
| 2251 |
thread storage duration ([[basic.stc.thread]]), for objects of type
|
| 2252 |
-
`std::type_info` ([[expr.typeid]]), or for
|
| 2253 |
-
|
| 2254 |
|
| 2255 |
#### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
|
| 2256 |
|
| 2257 |
Deallocation functions shall be class member functions or global
|
| 2258 |
functions; a program is ill-formed if deallocation functions are
|
| 2259 |
declared in a namespace scope other than global scope or declared static
|
| 2260 |
in global scope.
|
| 2261 |
|
| 2262 |
Each deallocation function shall return `void` and its first parameter
|
| 2263 |
shall be `void*`. A deallocation function can have more than one
|
| 2264 |
-
parameter.
|
| 2265 |
-
|
| 2266 |
-
|
| 2267 |
-
|
| 2268 |
-
|
| 2269 |
-
|
| 2270 |
-
|
| 2271 |
-
|
| 2272 |
-
`operator` `delete
|
| 2273 |
-
a usual
|
| 2274 |
-
|
| 2275 |
-
|
| 2276 |
-
|
| 2277 |
-
function
|
| 2278 |
-
|
| 2279 |
-
|
| 2280 |
-
|
| 2281 |
-
|
| 2282 |
-
|
| 2283 |
-
|
| 2284 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2285 |
|
| 2286 |
If a deallocation function terminates by throwing an exception, the
|
| 2287 |
behavior is undefined. The value of the first argument supplied to a
|
| 2288 |
deallocation function may be a null pointer value; if so, and if the
|
| 2289 |
deallocation function is one supplied in the standard library, the call
|
|
@@ -2299,31 +2342,34 @@ invocation of either `operator` `new[](std::size_t)` or `operator`
|
|
| 2299 |
|
| 2300 |
If the argument given to a deallocation function in the standard library
|
| 2301 |
is a pointer that is not the null pointer value ([[conv.ptr]]), the
|
| 2302 |
deallocation function shall deallocate the storage referenced by the
|
| 2303 |
pointer, rendering invalid all pointers referring to any part of the
|
| 2304 |
-
|
| 2305 |
-
|
|
|
|
|
|
|
| 2306 |
|
| 2307 |
#### Safely-derived pointers <a id="basic.stc.dynamic.safety">[[basic.stc.dynamic.safety]]</a>
|
| 2308 |
|
| 2309 |
A *traceable pointer object* is
|
| 2310 |
|
| 2311 |
- an object of an object pointer type ([[basic.compound]]), or
|
| 2312 |
- an object of an integral type that is at least as large as
|
| 2313 |
`std::intptr_t`, or
|
| 2314 |
-
- a sequence of elements in an array of character type
|
| 2315 |
-
|
|
|
|
| 2316 |
|
| 2317 |
A pointer value is a *safely-derived pointer* to a dynamic object only
|
| 2318 |
if it has an object pointer type and it is one of the following:
|
| 2319 |
|
| 2320 |
- the value returned by a call to the C++standard library implementation
|
| 2321 |
-
of `::operator new(std::size_t)`;[^
|
| 2322 |
- the result of taking the address of an object (or one of its
|
| 2323 |
-
subobjects) designated by an lvalue resulting from
|
| 2324 |
-
safely-derived pointer value;
|
| 2325 |
- the result of well-defined pointer arithmetic ([[expr.add]]) using a
|
| 2326 |
safely-derived pointer value;
|
| 2327 |
- the result of a well-defined pointer conversion ([[conv.ptr]],
|
| 2328 |
[[expr.cast]]) of a safely-derived pointer value;
|
| 2329 |
- the result of a `reinterpret_cast` of a safely-derived pointer value;
|
|
@@ -2350,16 +2396,16 @@ at least as large as `std::intptr_t` and it is one of the following:
|
|
| 2350 |
`reinterpret_cast<void*>(P)`.
|
| 2351 |
|
| 2352 |
An implementation may have *relaxed pointer safety*, in which case the
|
| 2353 |
validity of a pointer value does not depend on whether it is a
|
| 2354 |
safely-derived pointer value. Alternatively, an implementation may have
|
| 2355 |
-
*strict pointer safety*, in which case a pointer value
|
| 2356 |
-
|
| 2357 |
-
|
| 2358 |
-
previously been declared reachable (
|
| 2359 |
-
effect of using an invalid pointer value
|
| 2360 |
-
deallocation function) is undefined, see
|
| 2361 |
[[basic.stc.dynamic.deallocation]]. This is true even if the
|
| 2362 |
unsafely-derived pointer value might compare equal to some
|
| 2363 |
safely-derived pointer value. It is implementation defined whether an
|
| 2364 |
implementation has relaxed or strict pointer safety.
|
| 2365 |
|
|
@@ -2414,31 +2460,32 @@ the destructor or if a *delete-expression* ([[expr.delete]]) is not
|
|
| 2414 |
used to release the storage, the destructor shall not be implicitly
|
| 2415 |
called and any program that depends on the side effects produced by the
|
| 2416 |
destructor has undefined behavior.
|
| 2417 |
|
| 2418 |
Before the lifetime of an object has started but after the storage which
|
| 2419 |
-
the object will occupy has been allocated[^
|
| 2420 |
an object has ended and before the storage which the object occupied is
|
| 2421 |
reused or released, any pointer that refers to the storage location
|
| 2422 |
where the object will be or was located may be used but only in limited
|
| 2423 |
ways. For an object under construction or destruction, see
|
| 2424 |
[[class.cdtor]]. Otherwise, such a pointer refers to allocated storage (
|
| 2425 |
[[basic.stc.dynamic.deallocation]]), and using the pointer as if the
|
| 2426 |
-
pointer were of type `void*`, is well-defined.
|
| 2427 |
-
|
| 2428 |
-
as described below. The program has undefined behavior if:
|
| 2429 |
|
| 2430 |
- the object will be or was of a class type with a non-trivial
|
| 2431 |
destructor and the pointer is used as the operand of a
|
| 2432 |
*delete-expression*,
|
| 2433 |
- the pointer is used to access a non-static data member or call a
|
| 2434 |
non-static member function of the object, or
|
| 2435 |
- the pointer is implicitly converted ([[conv.ptr]]) to a pointer to a
|
| 2436 |
-
base class
|
| 2437 |
- the pointer is used as the operand of a `static_cast` (
|
| 2438 |
-
[[expr.static.cast]])
|
| 2439 |
-
`void
|
|
|
|
| 2440 |
- the pointer is used as the operand of a `dynamic_cast` (
|
| 2441 |
[[expr.dynamic.cast]]).
|
| 2442 |
``` cpp
|
| 2443 |
#include <cstdlib>
|
| 2444 |
|
|
@@ -2480,15 +2527,12 @@ undefined behavior if:
|
|
| 2480 |
|
| 2481 |
- an lvalue-to-rvalue conversion ([[conv.lval]]) is applied to such a
|
| 2482 |
glvalue,
|
| 2483 |
- the glvalue is used to access a non-static data member or call a
|
| 2484 |
non-static member function of the object, or
|
| 2485 |
-
- the glvalue is
|
| 2486 |
-
|
| 2487 |
-
- the glvalue is used as the operand of a `static_cast` (
|
| 2488 |
-
[[expr.static.cast]]) except when the conversion is ultimately to *cv*
|
| 2489 |
-
`char&` or *cv* `unsigned` `char&`, or
|
| 2490 |
- the glvalue is used as the operand of a `dynamic_cast` (
|
| 2491 |
[[expr.dynamic.cast]]) or as the operand of `typeid`.
|
| 2492 |
|
| 2493 |
If, after the lifetime of an object has ended and before the storage
|
| 2494 |
which the object occupied is reused or released, a new object is created
|
|
@@ -2531,11 +2575,11 @@ started, can be used to manipulate the new object, if:
|
|
| 2531 |
```
|
| 2532 |
|
| 2533 |
If a program ends the lifetime of an object of type `T` with static (
|
| 2534 |
[[basic.stc.static]]), thread ([[basic.stc.thread]]), or automatic (
|
| 2535 |
[[basic.stc.auto]]) storage duration and if `T` has a non-trivial
|
| 2536 |
-
destructor,[^
|
| 2537 |
type occupies that same storage location when the implicit destructor
|
| 2538 |
call takes place; otherwise the behavior of the program is undefined.
|
| 2539 |
This is true even if the block is exited with an exception.
|
| 2540 |
|
| 2541 |
``` cpp
|
|
@@ -2583,11 +2627,11 @@ objects ([[intro.object]]), references ([[dcl.ref]]), or functions (
|
|
| 2583 |
[[dcl.fct]]).
|
| 2584 |
|
| 2585 |
For any object (other than a base-class subobject) of trivially copyable
|
| 2586 |
type `T`, whether or not the object holds a valid value of type `T`, the
|
| 2587 |
underlying bytes ([[intro.memory]]) making up the object can be copied
|
| 2588 |
-
into an array of `char` or `unsigned` `char`.[^
|
| 2589 |
array of `char` or `unsigned` `char` is copied back into the object, the
|
| 2590 |
object shall subsequently hold its original value.
|
| 2591 |
|
| 2592 |
``` cpp
|
| 2593 |
#define N sizeof(T)
|
|
@@ -2600,11 +2644,11 @@ std::memcpy(&obj, buf, N); // at this point, each subobject of obj of scala
|
|
| 2600 |
```
|
| 2601 |
|
| 2602 |
For any trivially copyable type `T`, if two pointers to `T` point to
|
| 2603 |
distinct `T` objects `obj1` and `obj2`, where neither `obj1` nor `obj2`
|
| 2604 |
is a base-class subobject, if the underlying bytes ([[intro.memory]])
|
| 2605 |
-
making up `obj1` are copied into `obj2`,[^
|
| 2606 |
hold the same value as `obj1`.
|
| 2607 |
|
| 2608 |
``` cpp
|
| 2609 |
T* t1p;
|
| 2610 |
T* t2p;
|
|
@@ -2618,28 +2662,29 @@ The *object representation* of an object of type `T` is the sequence of
|
|
| 2618 |
*N* `unsigned` `char` objects taken up by the object of type `T`, where
|
| 2619 |
*N* equals `sizeof(T)`. The *value representation* of an object is the
|
| 2620 |
set of bits that hold the value of type `T`. For trivially copyable
|
| 2621 |
types, the value representation is a set of bits in the object
|
| 2622 |
representation that determines a *value*, which is one discrete element
|
| 2623 |
-
of an *implementation-defined* set of values.[^
|
| 2624 |
|
| 2625 |
-
A class that has been declared but not defined,
|
| 2626 |
-
|
| 2627 |
-
type
|
| 2628 |
-
|
| 2629 |
-
to have an
|
|
|
|
| 2630 |
|
| 2631 |
A class type (such as “`class X`”) might be incomplete at one point in a
|
| 2632 |
translation unit and complete later on; the type “`class X`” is the same
|
| 2633 |
type at both points. The declared type of an array object might be an
|
| 2634 |
array of incomplete class type and therefore incomplete; if the class
|
| 2635 |
type is completed later on in the translation unit, the array type
|
| 2636 |
becomes complete; the array type at those two points is the same type.
|
| 2637 |
The declared type of an array object might be an array of unknown size
|
| 2638 |
and therefore be incomplete at one point in a translation unit and
|
| 2639 |
complete later on; the array types at those two points (“array of
|
| 2640 |
-
unknown bound of `T`” and “array of N `T`”) are different types. The
|
| 2641 |
type of a pointer to array of unknown size, or of a type defined by a
|
| 2642 |
`typedef` declaration to be an array of unknown size, cannot be
|
| 2643 |
completed.
|
| 2644 |
|
| 2645 |
``` cpp
|
|
@@ -2678,37 +2723,35 @@ Arithmetic types ([[basic.fundamental]]), enumeration types, pointer
|
|
| 2678 |
types, pointer to member types ([[basic.compound]]), `std::nullptr_t`,
|
| 2679 |
and cv-qualified versions of these types ([[basic.type.qualifier]]) are
|
| 2680 |
collectively called *scalar types*. Scalar types, POD classes (Clause
|
| 2681 |
[[class]]), arrays of such types and *cv-qualified* versions of these
|
| 2682 |
types ([[basic.type.qualifier]]) are collectively called *POD types*.
|
| 2683 |
-
|
| 2684 |
-
of such types, and
|
| 2685 |
-
[[basic.type.qualifier]]) are collectively
|
| 2686 |
-
types*. Scalar types, trivial class types
|
| 2687 |
-
such types and cv-qualified versions of
|
| 2688 |
-
[[basic.type.qualifier]]) are collectively called *trivial
|
| 2689 |
-
Scalar types, standard-layout class types (Clause [[class]]),
|
| 2690 |
-
such types and cv-qualified versions of these types (
|
| 2691 |
[[basic.type.qualifier]]) are collectively called *standard-layout
|
| 2692 |
types*.
|
| 2693 |
|
| 2694 |
A type is a *literal type* if it is:
|
| 2695 |
|
|
|
|
| 2696 |
- a scalar type; or
|
| 2697 |
-
- a reference type
|
| 2698 |
- an array of literal type; or
|
| 2699 |
- a class type (Clause [[class]]) that has all of the following
|
| 2700 |
properties:
|
| 2701 |
- it has a trivial destructor,
|
| 2702 |
-
- every constructor call and full-expression in the
|
| 2703 |
-
*brace-or-equal-initializer*s for non-static data members (if any)
|
| 2704 |
-
is a constant expression ([[expr.const]]),
|
| 2705 |
- it is an aggregate type ([[dcl.init.aggr]]) or has at least one
|
| 2706 |
`constexpr` constructor or constructor template that is not a copy
|
| 2707 |
or move constructor, and
|
| 2708 |
-
- all of its non-static data members and base classes are of
|
| 2709 |
-
types.
|
| 2710 |
|
| 2711 |
If two types `T1` and `T2` are the same type, then `T1` and `T2` are
|
| 2712 |
*layout-compatible* types. Layout-compatible enumerations are described
|
| 2713 |
in [[dcl.enum]]. Layout-compatible standard-layout structs and
|
| 2714 |
standard-layout unions are described in [[class.mem]].
|
|
@@ -2720,38 +2763,43 @@ any member of the implementation’s basic character set. If a character
|
|
| 2720 |
from this set is stored in a character object, the integral value of
|
| 2721 |
that character object is equal to the value of the single character
|
| 2722 |
literal form of that character. It is *implementation-defined* whether a
|
| 2723 |
`char` object can hold negative values. Characters can be explicitly
|
| 2724 |
declared `unsigned` or `signed`. Plain `char`, `signed char`, and
|
| 2725 |
-
`unsigned char` are three distinct types
|
| 2726 |
-
|
| 2727 |
-
|
| 2728 |
-
|
|
|
|
| 2729 |
representation participate in the value representation. For unsigned
|
| 2730 |
-
character types, all possible bit patterns of the value
|
| 2731 |
-
represent numbers. These requirements do not hold for
|
| 2732 |
-
any particular implementation, a plain `char` object can
|
| 2733 |
-
the same values as a `signed char` or an `unsigned
|
| 2734 |
-
char`; which one is *implementation-defined*.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2735 |
|
| 2736 |
There are five *standard signed integer types* : “`signed char`”,
|
| 2737 |
“`short int`”, “`int`”, “`long int`”, and “`long` `long` `int`”. In this
|
| 2738 |
list, each type provides at least as much storage as those preceding it
|
| 2739 |
in the list. There may also be *implementation-defined* *extended signed
|
| 2740 |
integer types*. The standard and extended signed integer types are
|
| 2741 |
collectively called *signed integer types*. Plain `int`s have the
|
| 2742 |
natural size suggested by the architecture of the execution
|
| 2743 |
-
environment[^
|
| 2744 |
special needs.
|
| 2745 |
|
| 2746 |
For each of the standard signed integer types, there exists a
|
| 2747 |
corresponding (but different) *standard unsigned integer type*:
|
| 2748 |
“`unsigned char`”, “`unsigned short int`”, “`unsigned int`”,
|
| 2749 |
“`unsigned long int`”, and “`unsigned` `long` `long` `int`”, each of
|
| 2750 |
which occupies the same amount of storage and has the same alignment
|
| 2751 |
requirements ([[basic.align]]) as the corresponding signed integer
|
| 2752 |
-
type[^
|
| 2753 |
representation as its corresponding unsigned integer type. Likewise, for
|
| 2754 |
each of the extended signed integer types there exists a corresponding
|
| 2755 |
*extended unsigned integer type* with the same amount of storage and
|
| 2756 |
alignment requirements. The standard and extended unsigned integer types
|
| 2757 |
are collectively called *unsigned integer types*. The range of
|
|
@@ -2759,34 +2807,36 @@ non-negative values of a *signed integer* type is a subrange of the
|
|
| 2759 |
corresponding *unsigned integer* type, and the value representation of
|
| 2760 |
each corresponding signed/unsigned type shall be the same. The standard
|
| 2761 |
signed integer types and standard unsigned integer types are
|
| 2762 |
collectively called the *standard integer types*, and the extended
|
| 2763 |
signed integer types and extended unsigned integer types are
|
| 2764 |
-
collectively called the *extended integer types*.
|
|
|
|
|
|
|
| 2765 |
|
| 2766 |
-
Unsigned integers
|
| 2767 |
-
|
| 2768 |
-
|
| 2769 |
|
| 2770 |
Type `wchar_t` is a distinct type whose values can represent distinct
|
| 2771 |
codes for all members of the largest extended character set specified
|
| 2772 |
among the supported locales ([[locale]]). Type `wchar_t` shall have the
|
| 2773 |
same size, signedness, and alignment requirements ([[basic.align]]) as
|
| 2774 |
one of the other integral types, called its *underlying type*. Types
|
| 2775 |
`char16_t` and `char32_t` denote distinct types with the same size,
|
| 2776 |
signedness, and alignment as `uint_least16_t` and `uint_least32_t`,
|
| 2777 |
-
respectively, in `<
|
| 2778 |
|
| 2779 |
-
Values of type `bool` are either `true` or `false`.[^
|
| 2780 |
`signed`, `unsigned`, `short`, or `long bool` types or values. Values of
|
| 2781 |
type `bool` participate in integral promotions ([[conv.prom]]).
|
| 2782 |
|
| 2783 |
Types `bool`, `char`, `char16_t`, `char32_t`, `wchar_t`, and the signed
|
| 2784 |
and unsigned integer types are collectively called *integral*
|
| 2785 |
-
types.[^
|
| 2786 |
representations of integral types shall define values by use of a pure
|
| 2787 |
-
binary numeration system.[^
|
| 2788 |
complement, 1’s complement and signed magnitude representations for
|
| 2789 |
integral types.
|
| 2790 |
|
| 2791 |
There are three *floating point* types: `float`, `double`, and
|
| 2792 |
`long double`. The type `double` provides at least as much precision as
|
|
@@ -2806,13 +2856,13 @@ incomplete type that cannot be completed. It is used as the return type
|
|
| 2806 |
for functions that do not return a value. Any expression can be
|
| 2807 |
explicitly converted to type *cv* `void` ([[expr.cast]]). An expression
|
| 2808 |
of type `void` shall be used only as an expression statement (
|
| 2809 |
[[stmt.expr]]), as an operand of a comma expression ([[expr.comma]]),
|
| 2810 |
as a second or third operand of `?:` ([[expr.cond]]), as the operand of
|
| 2811 |
-
`typeid` or `decltype`, as the expression in a return
|
| 2812 |
-
[[stmt.return]]) for a function with the return type `void`,
|
| 2813 |
-
operand of an explicit conversion to type cv `void`.
|
| 2814 |
|
| 2815 |
A value of type `std::nullptr_t` is a null pointer constant (
|
| 2816 |
[[conv.ptr]]). Such values participate in the pointer and the pointer to
|
| 2817 |
member conversions ([[conv.ptr]], [[conv.mem]]).
|
| 2818 |
`sizeof(std::nullptr_t)` shall be equal to `sizeof(void*)`.
|
|
@@ -2841,16 +2891,18 @@ Compound types can be constructed in the following ways:
|
|
| 2841 |
- *unions*, which are classes capable of containing objects of different
|
| 2842 |
types at different times, [[class.union]];
|
| 2843 |
- *enumerations*, which comprise a set of named constant values. Each
|
| 2844 |
distinct enumeration constitutes a different *enumerated type*,
|
| 2845 |
[[dcl.enum]];
|
| 2846 |
-
- *pointers to non-static* [^
|
| 2847 |
of a given type within objects of a given class, [[dcl.mptr]].
|
| 2848 |
|
| 2849 |
These methods of constructing types can be applied recursively;
|
| 2850 |
restrictions are mentioned in [[dcl.ptr]], [[dcl.array]], [[dcl.fct]],
|
| 2851 |
-
and [[dcl.ref]].
|
|
|
|
|
|
|
| 2852 |
|
| 2853 |
The type of a pointer to `void` or a pointer to an object type is called
|
| 2854 |
an *object pointer type*. A pointer to `void` does not have a
|
| 2855 |
pointer-to-object type, however, because `void` is not an object type.
|
| 2856 |
The type of a pointer that can designate a function is called a
|
|
@@ -2894,32 +2946,33 @@ A type mentioned in [[basic.fundamental]] and [[basic.compound]] is a
|
|
| 2894 |
*cv-unqualified type*. Each type which is a cv-unqualified complete or
|
| 2895 |
incomplete object type or is `void` ([[basic.types]]) has three
|
| 2896 |
corresponding cv-qualified versions of its type: a *const-qualified*
|
| 2897 |
version, a *volatile-qualified* version, and a
|
| 2898 |
*const-volatile-qualified* version. The term *object type* (
|
| 2899 |
-
[[intro.object]]) includes the cv-qualifiers specified
|
| 2900 |
-
|
| 2901 |
-
|
| 2902 |
-
|
| 2903 |
-
|
| 2904 |
-
|
| 2905 |
-
|
| 2906 |
-
|
| 2907 |
-
object
|
| 2908 |
-
|
| 2909 |
-
|
| 2910 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2911 |
|
| 2912 |
A compound type ([[basic.compound]]) is not cv-qualified by the
|
| 2913 |
cv-qualifiers (if any) of the types from which it is compounded. Any
|
| 2914 |
cv-qualifiers applied to an array type affect the array element type,
|
| 2915 |
not the array type ([[dcl.array]]).
|
| 2916 |
|
| 2917 |
-
Each non-static, non-mutable, non-reference data member of a
|
| 2918 |
-
const-qualified class object is const-qualified, each non-static,
|
| 2919 |
-
non-reference data member of a volatile-qualified class object is
|
| 2920 |
-
volatile-qualified and similarly for members of a const-volatile class.
|
| 2921 |
See [[dcl.fct]] and [[class.this]] regarding function types that have
|
| 2922 |
*cv-qualifier*s.
|
| 2923 |
|
| 2924 |
There is a partial ordering on cv-qualifiers, so that a type can be said
|
| 2925 |
to be *more cv-qualified* than another. Table
|
|
@@ -2941,13 +2994,22 @@ In this International Standard, the notation *cv* (or *cv1*, *cv2*,
|
|
| 2941 |
etc.), used in the description of types, represents an arbitrary set of
|
| 2942 |
cv-qualifiers, i.e., one of {`const`}, {`volatile`}, {`const`,
|
| 2943 |
`volatile`}, or the empty set. Cv-qualifiers applied to an array type
|
| 2944 |
attach to the underlying element type, so the notation “*cv* `T`,” where
|
| 2945 |
`T` is an array type, refers to an array whose elements are
|
| 2946 |
-
so-qualified.
|
| 2947 |
-
|
| 2948 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2949 |
|
| 2950 |
## Lvalues and rvalues <a id="basic.lval">[[basic.lval]]</a>
|
| 2951 |
|
| 2952 |
Expressions are categorized according to the taxonomy in Figure
|
| 2953 |
[[fig:categories]].
|
|
@@ -2964,11 +3026,12 @@ Expressions are categorized according to the taxonomy in Figure
|
|
| 2964 |
return type is an lvalue reference is an lvalue.
|
| 2965 |
- An *xvalue* (an “eXpiring” value) also refers to an object, usually
|
| 2966 |
near the end of its lifetime (so that its resources may be moved, for
|
| 2967 |
example). An xvalue is the result of certain kinds of expressions
|
| 2968 |
involving rvalue references ([[dcl.ref]]). The result of calling a
|
| 2969 |
-
function whose return type is an rvalue reference
|
|
|
|
| 2970 |
- A *glvalue* (“generalized” lvalue) is an lvalue or an xvalue.
|
| 2971 |
- An *rvalue* (so called, historically, because rvalues could appear on
|
| 2972 |
the right-hand side of an assignment expression) is an xvalue, a
|
| 2973 |
temporary object ([[class.temporary]]) or subobject thereof, or a
|
| 2974 |
value that is not associated with an object.
|
|
@@ -2995,14 +3058,15 @@ is not such a context; see [[dcl.init.ref]].
|
|
| 2995 |
|
| 2996 |
The discussion of reference initialization in [[dcl.init.ref]] and of
|
| 2997 |
temporaries in [[class.temporary]] indicates the behavior of lvalues
|
| 2998 |
and rvalues in other significant contexts.
|
| 2999 |
|
| 3000 |
-
|
| 3001 |
-
|
| 3002 |
-
|
| 3003 |
-
|
|
|
|
| 3004 |
|
| 3005 |
An lvalue for an object is necessary in order to modify the object
|
| 3006 |
except that an rvalue of class type can also be used to modify its
|
| 3007 |
referent under certain circumstances. a member function called for an
|
| 3008 |
object ([[class.mfct]]) can modify the object.
|
|
@@ -3023,11 +3087,11 @@ the expression is called *modifiable*. A program that attempts to modify
|
|
| 3023 |
an object through a nonmodifiable lvalue or rvalue expression is
|
| 3024 |
ill-formed.
|
| 3025 |
|
| 3026 |
If a program attempts to access the stored value of an object through a
|
| 3027 |
glvalue of other than one of the following types the behavior is
|
| 3028 |
-
undefined:[^
|
| 3029 |
|
| 3030 |
- the dynamic type of the object,
|
| 3031 |
- a cv-qualified version of the dynamic type of the object,
|
| 3032 |
- a type similar (as defined in [[conv.qual]]) to the dynamic type of
|
| 3033 |
the object,
|
|
@@ -3092,14 +3156,14 @@ Alignments have an order from *weaker* to *stronger* or *stricter*
|
|
| 3092 |
alignments. Stricter alignments have larger alignment values. An address
|
| 3093 |
that satisfies an alignment requirement also satisfies any weaker valid
|
| 3094 |
alignment requirement.
|
| 3095 |
|
| 3096 |
The alignment requirement of a complete type can be queried using an
|
| 3097 |
-
`alignof` expression ([[expr.alignof]]). Furthermore, the
|
| 3098 |
-
|
| 3099 |
-
requirement. This enables the character types to be
|
| 3100 |
-
underlying type for an aligned memory area ([[dcl.align]]).
|
| 3101 |
|
| 3102 |
Comparing alignments is meaningful and provides the obvious results:
|
| 3103 |
|
| 3104 |
- Two alignments are equal when their numeric values are equal.
|
| 3105 |
- Two alignments are different when their numeric values are not equal.
|
|
@@ -3136,15 +3200,15 @@ allocation failure.
|
|
| 3136 |
[basic.lookup.udir]: #basic.lookup.udir
|
| 3137 |
[basic.lookup.unqual]: #basic.lookup.unqual
|
| 3138 |
[basic.lval]: #basic.lval
|
| 3139 |
[basic.namespace]: dcl.md#basic.namespace
|
| 3140 |
[basic.scope]: #basic.scope
|
|
|
|
| 3141 |
[basic.scope.class]: #basic.scope.class
|
| 3142 |
[basic.scope.declarative]: #basic.scope.declarative
|
| 3143 |
[basic.scope.enum]: #basic.scope.enum
|
| 3144 |
[basic.scope.hiding]: #basic.scope.hiding
|
| 3145 |
-
[basic.scope.local]: #basic.scope.local
|
| 3146 |
[basic.scope.namespace]: #basic.scope.namespace
|
| 3147 |
[basic.scope.pdecl]: #basic.scope.pdecl
|
| 3148 |
[basic.scope.proto]: #basic.scope.proto
|
| 3149 |
[basic.scope.temp]: #basic.scope.temp
|
| 3150 |
[basic.start]: #basic.start
|
|
@@ -3187,18 +3251,18 @@ allocation failure.
|
|
| 3187 |
[class.this]: class.md#class.this
|
| 3188 |
[class.union]: class.md#class.union
|
| 3189 |
[conv]: conv.md#conv
|
| 3190 |
[conv.array]: conv.md#conv.array
|
| 3191 |
[conv.func]: conv.md#conv.func
|
|
|
|
| 3192 |
[conv.lval]: conv.md#conv.lval
|
| 3193 |
[conv.mem]: conv.md#conv.mem
|
| 3194 |
[conv.prom]: conv.md#conv.prom
|
| 3195 |
[conv.ptr]: conv.md#conv.ptr
|
| 3196 |
[conv.qual]: conv.md#conv.qual
|
| 3197 |
[dcl.align]: dcl.md#dcl.align
|
| 3198 |
[dcl.array]: dcl.md#dcl.array
|
| 3199 |
-
[dcl.constexpr]: dcl.md#dcl.constexpr
|
| 3200 |
[dcl.dcl]: dcl.md#dcl.dcl
|
| 3201 |
[dcl.decl]: dcl.md#dcl.decl
|
| 3202 |
[dcl.enum]: dcl.md#dcl.enum
|
| 3203 |
[dcl.fct]: dcl.md#dcl.fct
|
| 3204 |
[dcl.fct.def]: dcl.md#dcl.fct.def
|
|
@@ -3207,17 +3271,20 @@ allocation failure.
|
|
| 3207 |
[dcl.init]: dcl.md#dcl.init
|
| 3208 |
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 3209 |
[dcl.init.ref]: dcl.md#dcl.init.ref
|
| 3210 |
[dcl.link]: dcl.md#dcl.link
|
| 3211 |
[dcl.mptr]: dcl.md#dcl.mptr
|
|
|
|
| 3212 |
[dcl.ptr]: dcl.md#dcl.ptr
|
| 3213 |
[dcl.ref]: dcl.md#dcl.ref
|
|
|
|
| 3214 |
[dcl.stc]: dcl.md#dcl.stc
|
| 3215 |
[dcl.type.cv]: dcl.md#dcl.type.cv
|
| 3216 |
[dcl.type.elab]: dcl.md#dcl.type.elab
|
| 3217 |
[dcl.type.simple]: dcl.md#dcl.type.simple
|
| 3218 |
[dcl.typedef]: dcl.md#dcl.typedef
|
|
|
|
| 3219 |
[except]: except.md#except
|
| 3220 |
[except.handle]: except.md#except.handle
|
| 3221 |
[except.spec]: except.md#except.spec
|
| 3222 |
[except.terminate]: except.md#except.terminate
|
| 3223 |
[except.throw]: except.md#except.throw
|
|
@@ -3230,12 +3297,14 @@ allocation failure.
|
|
| 3230 |
[expr.comma]: expr.md#expr.comma
|
| 3231 |
[expr.cond]: expr.md#expr.cond
|
| 3232 |
[expr.const]: expr.md#expr.const
|
| 3233 |
[expr.delete]: expr.md#expr.delete
|
| 3234 |
[expr.dynamic.cast]: expr.md#expr.dynamic.cast
|
|
|
|
| 3235 |
[expr.new]: expr.md#expr.new
|
| 3236 |
[expr.prim]: expr.md#expr.prim
|
|
|
|
| 3237 |
[expr.pseudo]: expr.md#expr.pseudo
|
| 3238 |
[expr.ref]: expr.md#expr.ref
|
| 3239 |
[expr.sizeof]: expr.md#expr.sizeof
|
| 3240 |
[expr.static.cast]: expr.md#expr.static.cast
|
| 3241 |
[expr.type.conv]: expr.md#expr.type.conv
|
|
@@ -3262,10 +3331,11 @@ allocation failure.
|
|
| 3262 |
[over]: over.md#over
|
| 3263 |
[over.literal]: over.md#over.literal
|
| 3264 |
[over.load]: over.md#over.load
|
| 3265 |
[over.match]: over.md#over.match
|
| 3266 |
[over.oper]: over.md#over.oper
|
|
|
|
| 3267 |
[ptr.align]: utilities.md#ptr.align
|
| 3268 |
[replacement.functions]: library.md#replacement.functions
|
| 3269 |
[set.new.handler]: language.md#set.new.handler
|
| 3270 |
[stmt.block]: stmt.md#stmt.block
|
| 3271 |
[stmt.dcl]: stmt.md#stmt.dcl
|
|
@@ -3324,93 +3394,101 @@ allocation failure.
|
|
| 3324 |
[^6]: This lookup applies whether the definition of `X` is nested within
|
| 3325 |
`Y`’s definition or whether `X`’s definition appears in a namespace
|
| 3326 |
scope enclosing `Y` ’s definition ([[class.nest]]).
|
| 3327 |
|
| 3328 |
[^7]: That is, an unqualified name that occurs, for instance, in a type
|
| 3329 |
-
|
| 3330 |
-
|
| 3331 |
|
| 3332 |
[^8]: This lookup applies whether the member function is defined within
|
| 3333 |
the definition of class `X` or whether the member function is
|
| 3334 |
defined in a namespace scope enclosing `X`’s definition.
|
| 3335 |
|
| 3336 |
-
[^9]:
|
| 3337 |
-
|
| 3338 |
-
|
| 3339 |
|
| 3340 |
-
[^10]: A
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3341 |
initialization with side-effects must be initialized even if it is
|
| 3342 |
not odr-used ([[basic.def.odr]], [[basic.stc.static]]).
|
| 3343 |
|
| 3344 |
-
[^
|
| 3345 |
`std::malloc()` or `std::calloc()`, so the rules are substantially
|
| 3346 |
the same. C++differs from C in requiring a zero request to return a
|
| 3347 |
non-null pointer.
|
| 3348 |
|
| 3349 |
-
[^
|
| 3350 |
-
|
|
|
|
| 3351 |
|
| 3352 |
-
[^
|
|
|
|
|
|
|
|
|
|
| 3353 |
pointers to memory not allocated by `::operator new`. This maintains
|
| 3354 |
the ability of many C++implementations to use binary libraries and
|
| 3355 |
components written in other languages. In particular, this applies
|
| 3356 |
-
to C binaries, because
|
| 3357 |
-
`malloc` is not restricted.
|
| 3358 |
|
| 3359 |
-
[^
|
| 3360 |
non-POD class type ([[class.cdtor]]).
|
| 3361 |
|
| 3362 |
-
[^
|
| 3363 |
implicitly—upon exit from the block for an object with automatic
|
| 3364 |
storage duration, upon exit from the thread for an object with
|
| 3365 |
thread storage duration, or upon exit from the program for an object
|
| 3366 |
with static storage duration.
|
| 3367 |
|
| 3368 |
-
[^
|
| 3369 |
`std::memcpy` or `std::memmove`.
|
| 3370 |
|
| 3371 |
-
[^
|
| 3372 |
`std::memcpy` or `std::memmove`.
|
| 3373 |
|
| 3374 |
-
[^
|
| 3375 |
of ISO/IEC 9899 Programming Language C.
|
| 3376 |
|
| 3377 |
-
[^
|
| 3378 |
object type is unknown.
|
| 3379 |
|
| 3380 |
-
[^
|
| 3381 |
`INT_MIN` and `INT_MAX`, as defined in the header `<climits>`.
|
| 3382 |
|
| 3383 |
-
[^
|
| 3384 |
types and the sequences of *type-specifier*s that designate them.
|
| 3385 |
|
| 3386 |
-
[^
|
| 3387 |
result that cannot be represented by the resulting unsigned integer
|
| 3388 |
type is reduced modulo the number that is one greater than the
|
| 3389 |
largest value that can be represented by the resulting unsigned
|
| 3390 |
integer type.
|
| 3391 |
|
| 3392 |
-
[^
|
| 3393 |
Standard as “undefined,” such as by examining the value of an
|
| 3394 |
uninitialized automatic object, might cause it to behave as if it is
|
| 3395 |
neither `true` nor `false`.
|
| 3396 |
|
| 3397 |
-
[^
|
| 3398 |
however, enumerations can be promoted to integral types as specified
|
| 3399 |
in [[conv.prom]].
|
| 3400 |
|
| 3401 |
-
[^
|
| 3402 |
digits 0 and 1, in which the values represented by successive bits
|
| 3403 |
are additive, begin with 1, and are multiplied by successive
|
| 3404 |
integral power of 2, except perhaps for the bit with the highest
|
| 3405 |
position. (Adapted from the *American National Dictionary for
|
| 3406 |
Information Processing Systems*.)
|
| 3407 |
|
| 3408 |
-
[^
|
| 3409 |
them are ordinary pointers to objects or functions.
|
| 3410 |
|
| 3411 |
-
[^
|
| 3412 |
imply interchangeability as arguments to functions, return values
|
| 3413 |
from functions, and non-static data members of unions.
|
| 3414 |
|
| 3415 |
-
[^
|
| 3416 |
which an object may or may not be aliased.
|
|
|
|
| 25 |
Every name that denotes an entity is introduced by a *declaration*.
|
| 26 |
Every name that denotes a label is introduced either by a `goto`
|
| 27 |
statement ([[stmt.goto]]) or a *labeled-statement* ([[stmt.label]]).
|
| 28 |
|
| 29 |
A *variable* is introduced by the declaration of a reference other than
|
| 30 |
+
a non-static data member or of an object. The variable’s name, if any,
|
| 31 |
+
denotes the reference or object.
|
| 32 |
|
| 33 |
Some names denote types or templates. In general, whenever a name is
|
| 34 |
encountered it is necessary to determine whether that name denotes one
|
| 35 |
of these entities before continuing to parse the program that contains
|
| 36 |
it. The process that determines this is called *name lookup* (
|
|
|
|
| 39 |
Two names are *the same* if
|
| 40 |
|
| 41 |
- they are *identifier*s composed of the same character sequence, or
|
| 42 |
- they are *operator-function-id*s formed with the same operator, or
|
| 43 |
- they are *conversion-function-id*s formed with the same type, or
|
| 44 |
+
- they are *template-id*s that refer to the same class, function, or
|
| 45 |
+
variable ([[temp.type]]), or
|
| 46 |
- they are the names of literal operators ([[over.literal]]) formed
|
| 47 |
with the same literal suffix identifier.
|
| 48 |
|
| 49 |
A name used in more than one translation unit can potentially refer to
|
| 50 |
the same entity in these translation units depending on the linkage (
|
|
|
|
| 157 |
|
| 158 |
No translation unit shall contain more than one definition of any
|
| 159 |
variable, function, class type, enumeration type, or template.
|
| 160 |
|
| 161 |
An expression is *potentially evaluated* unless it is an unevaluated
|
| 162 |
+
operand (Clause [[expr]]) or a subexpression thereof. The set of
|
| 163 |
+
*potential results* of an expression `e` is defined as follows:
|
| 164 |
+
|
| 165 |
+
- If `e` is an *id-expression* ([[expr.prim.general]]), the set
|
| 166 |
+
contains only `e`.
|
| 167 |
+
- If `e` is a class member access expression ([[expr.ref]]), the set
|
| 168 |
+
contains the potential results of the object expression.
|
| 169 |
+
- If `e` is a pointer-to-member expression ([[expr.mptr.oper]]) whose
|
| 170 |
+
second operand is a constant expression, the set contains the
|
| 171 |
+
potential results of the object expression.
|
| 172 |
+
- If `e` has the form `(e1)`, the set contains the potential results of
|
| 173 |
+
`e1`.
|
| 174 |
+
- If `e` is a glvalue conditional expression ([[expr.cond]]), the set
|
| 175 |
+
is the union of the sets of potential results of the second and third
|
| 176 |
+
operands.
|
| 177 |
+
- If `e` is a comma expression ([[expr.comma]]), the set contains the
|
| 178 |
+
potential results of the right operand.
|
| 179 |
+
- Otherwise, the set is empty.
|
| 180 |
+
|
| 181 |
+
This set is a (possibly-empty) set of *id-expression*s, each of which is
|
| 182 |
+
either `e` or a subexpression of `e`. In the following example, the set
|
| 183 |
+
of potential results of the initializer of `n` contains the first `S::x`
|
| 184 |
+
subexpression, but not the second `S::x` subexpression.
|
| 185 |
+
|
| 186 |
+
``` cpp
|
| 187 |
+
struct S { static const int x = 0; };
|
| 188 |
+
const int &f(const int &r);
|
| 189 |
+
int n = b ? (1, S::x) // S::x is not odr-used here
|
| 190 |
+
: f(S::x); // S::x is odr-used here, so
|
| 191 |
+
// a definition is required
|
| 192 |
+
```
|
| 193 |
+
|
| 194 |
+
A variable `x` whose name appears as a potentially-evaluated expression
|
| 195 |
+
`ex` is *odr-used* by `ex` unless applying the lvalue-to-rvalue
|
| 196 |
+
conversion ([[conv.lval]]) to `x` yields a constant expression (
|
| 197 |
+
[[expr.const]]) that does not invoke any non-trivial functions and, if
|
| 198 |
+
`x` is an object, `ex` is an element of the set of potential results of
|
| 199 |
+
an expression `e`, where either the lvalue-to-rvalue conversion (
|
| 200 |
+
[[conv.lval]]) is applied to `e`, or `e` is a discarded-value
|
| 201 |
+
expression (Clause [[expr]]). `this` is odr-used if it appears as a
|
| 202 |
+
potentially-evaluated expression (including as the result of the
|
| 203 |
+
implicit transformation in the body of a non-static member function (
|
| 204 |
+
[[class.mfct.non-static]])). A virtual member function is odr-used if it
|
| 205 |
+
is not pure. A function whose name appears as a potentially-evaluated
|
| 206 |
+
expression is odr-used if it is the unique lookup result or the selected
|
| 207 |
+
member of a set of overloaded functions ([[basic.lookup]],
|
| 208 |
+
[[over.match]], [[over.over]]), unless it is a pure virtual function and
|
| 209 |
+
its name is not explicitly qualified. This covers calls to named
|
| 210 |
+
functions ([[expr.call]]), operator overloading (Clause [[over]]),
|
| 211 |
+
user-defined conversions ([[class.conv.fct]]), allocation function for
|
| 212 |
+
placement new ([[expr.new]]), as well as non-default initialization (
|
| 213 |
+
[[dcl.init]]). A constructor selected to copy or move an object of class
|
| 214 |
+
type is odr-used even if the call is actually elided by the
|
| 215 |
+
implementation ([[class.copy]]). An allocation or deallocation function
|
| 216 |
+
for a class is odr-used by a new expression appearing in a
|
| 217 |
+
potentially-evaluated expression as specified in [[expr.new]] and
|
| 218 |
+
[[class.free]]. A deallocation function for a class is odr-used by a
|
| 219 |
+
delete expression appearing in a potentially-evaluated expression as
|
| 220 |
+
specified in [[expr.delete]] and [[class.free]]. A non-placement
|
| 221 |
+
allocation or deallocation function for a class is odr-used by the
|
| 222 |
+
definition of a constructor of that class. A non-placement deallocation
|
| 223 |
+
function for a class is odr-used by the definition of the destructor of
|
| 224 |
+
that class, or by being selected by the lookup at the point of
|
| 225 |
+
definition of a virtual destructor ([[class.dtor]]).[^2] An assignment
|
| 226 |
+
operator function in a class is odr-used by an implicitly-defined
|
| 227 |
+
copy-assignment or move-assignment function for another class as
|
| 228 |
+
specified in [[class.copy]]. A default constructor for a class is
|
| 229 |
+
odr-used by default initialization or value initialization as specified
|
| 230 |
+
in [[dcl.init]]. A constructor for a class is odr-used as specified in
|
| 231 |
+
[[dcl.init]]. A destructor for a class is odr-used if it is potentially
|
| 232 |
+
invoked ([[class.dtor]]).
|
| 233 |
|
| 234 |
Every program shall contain exactly one definition of every non-inline
|
| 235 |
function or variable that is odr-used in that program; no diagnostic
|
| 236 |
required. The definition can appear explicitly in the program, it can be
|
| 237 |
found in the standard or a user-defined library, or (when appropriate)
|
|
|
|
| 262 |
object of type `T` ([[conv.lval]]), or
|
| 263 |
- an expression is converted (either implicitly or explicitly) to type
|
| 264 |
`T` (Clause [[conv]], [[expr.type.conv]], [[expr.dynamic.cast]],
|
| 265 |
[[expr.static.cast]], [[expr.cast]]), or
|
| 266 |
- an expression that is not a null pointer constant, and has type other
|
| 267 |
+
than *cv* `void*`, is converted to the type pointer to `T` or
|
| 268 |
+
reference to `T` using a standard conversion (Clause [[conv]]), a
|
| 269 |
`dynamic_cast` ([[expr.dynamic.cast]]) or a `static_cast` (
|
| 270 |
[[expr.static.cast]]), or
|
| 271 |
- a class member access operator is applied to an expression of type
|
| 272 |
`T` ([[expr.ref]]), or
|
| 273 |
- the `typeid` operator ([[expr.typeid]]) or the `sizeof` operator (
|
|
|
|
| 299 |
- in each definition of `D`, corresponding names, looked up according
|
| 300 |
to [[basic.lookup]], shall refer to an entity defined within the
|
| 301 |
definition of `D`, or shall refer to the same entity, after overload
|
| 302 |
resolution ([[over.match]]) and after matching of partial template
|
| 303 |
specialization ([[temp.over]]), except that a name can refer to a
|
| 304 |
+
non-volatile `const` object with internal or no linkage if the object
|
| 305 |
+
has the same literal type in all definitions of `D`, and the object is
|
| 306 |
+
initialized with a constant expression ([[expr.const]]), and the
|
| 307 |
+
object is not odr-used, and the object has the same value in all
|
| 308 |
+
definitions of `D`; and
|
| 309 |
- in each definition of `D`, corresponding entities shall have the same
|
| 310 |
language linkage; and
|
| 311 |
- in each definition of `D`, the overloaded operators referred to, the
|
| 312 |
implicit calls to conversion functions, constructors, operator new
|
| 313 |
functions and operator delete functions, shall refer to the same
|
|
|
|
| 347 |
If `D` is a template and is defined in more than one translation unit,
|
| 348 |
then the preceding requirements shall apply both to names from the
|
| 349 |
template’s enclosing scope used in the template definition (
|
| 350 |
[[temp.nondep]]), and also to dependent names at the point of
|
| 351 |
instantiation ([[temp.dep]]). If the definitions of `D` satisfy all
|
| 352 |
+
these requirements, then the behavior is as if there were a single
|
| 353 |
+
definition of `D`. If the definitions of `D` do not satisfy these
|
| 354 |
requirements, then the behavior is undefined.
|
| 355 |
|
| 356 |
## Scope <a id="basic.scope">[[basic.scope]]</a>
|
| 357 |
|
| 358 |
### Declarative regions and scopes <a id="basic.scope.declarative">[[basic.scope.declarative]]</a>
|
|
|
|
| 426 |
The *point of declaration* for a name is immediately after its complete
|
| 427 |
declarator (Clause [[dcl.decl]]) and before its *initializer* (if any),
|
| 428 |
except as noted below.
|
| 429 |
|
| 430 |
``` cpp
|
| 431 |
+
unsigned char x = 12;
|
| 432 |
+
{ unsigned char x = x; }
|
| 433 |
```
|
| 434 |
|
| 435 |
Here the second `x` is initialized with its own (indeterminate) value.
|
| 436 |
|
| 437 |
a name from an outer scope remains visible up to the point of
|
|
|
|
| 451 |
*identifier* (if any) in either its *enum-specifier* ([[dcl.enum]]) or
|
| 452 |
its first *opaque-enum-declaration* ([[dcl.enum]]), whichever comes
|
| 453 |
first. The point of declaration of an alias or alias template
|
| 454 |
immediately follows the *type-id* to which the alias refers.
|
| 455 |
|
| 456 |
+
The point of declaration of a *using-declaration* that does not name a
|
| 457 |
+
constructor is immediately after the *using-declaration* (
|
| 458 |
+
[[namespace.udecl]]).
|
| 459 |
+
|
| 460 |
The point of declaration for an enumerator is immediately after its
|
| 461 |
*enumerator-definition*.
|
| 462 |
|
| 463 |
``` cpp
|
| 464 |
const int x = 12;
|
|
|
|
| 530 |
block scope refer to declarations that are members of an enclosing
|
| 531 |
namespace, but they do not introduce new names into that scope.
|
| 532 |
|
| 533 |
For point of instantiation of a template, see [[temp.point]].
|
| 534 |
|
| 535 |
+
### Block scope <a id="basic.scope.block">[[basic.scope.block]]</a>
|
| 536 |
|
| 537 |
A name declared in a block ([[stmt.block]]) is local to that block; it
|
| 538 |
has *block scope*. Its potential scope begins at its point of
|
| 539 |
declaration ([[basic.scope.pdecl]]) and ends at the end of its block. A
|
| 540 |
variable declared at block scope is a *local variable*.
|
|
|
|
| 626 |
The outermost declarative region of a translation unit is also a
|
| 627 |
namespace, called the *global namespace*. A name declared in the global
|
| 628 |
namespace has *global namespace scope* (also called *global scope*). The
|
| 629 |
potential scope of such a name begins at its point of declaration (
|
| 630 |
[[basic.scope.pdecl]]) and ends at the end of the translation unit that
|
| 631 |
+
is its declarative region. A name with global namespace scope is said to
|
| 632 |
+
be a *global name*.
|
| 633 |
|
| 634 |
### Class scope <a id="basic.scope.class">[[basic.scope.class]]</a>
|
| 635 |
|
| 636 |
The following rules describe the scope of names declared in classes.
|
| 637 |
|
|
|
|
| 852 |
// 4) global scope, before the definition of A::N::f
|
| 853 |
}
|
| 854 |
```
|
| 855 |
|
| 856 |
A name used in the definition of a class `X` outside of a member
|
| 857 |
+
function body, default argument, *exception-specification*,
|
| 858 |
+
*brace-or-equal-initializer* of a non-static data member, or nested
|
| 859 |
+
class definition[^5] shall be declared in one of the following ways:
|
| 860 |
|
| 861 |
- before its use in class `X` or be a member of a base class of `X` (
|
| 862 |
[[class.member.lookup]]), or
|
| 863 |
- if `X` is a nested class of class `Y` ([[class.nest]]), before the
|
| 864 |
definition of `X` in `Y`, or shall be a member of a base class of `Y`
|
|
|
|
| 903 |
names in a class definition. [[class.nest]] further describes the
|
| 904 |
restrictions on the use of names in nested class definitions.
|
| 905 |
[[class.local]] further describes the restrictions on the use of names
|
| 906 |
in local class definitions.
|
| 907 |
|
| 908 |
+
For the members of a class `X`, a name used in a member function body,
|
| 909 |
+
in a default argument, in an *exception-specification*, in the
|
| 910 |
*brace-or-equal-initializer* of a non-static data member (
|
| 911 |
+
[[class.mem]]), or in the definition of a class member outside of the
|
| 912 |
+
definition of `X`, following the member’s *declarator-id*[^7], shall be
|
| 913 |
+
declared in one of the following ways:
|
| 914 |
|
| 915 |
- before its use in the block in which it is used or in an enclosing
|
| 916 |
block ([[stmt.block]]), or
|
| 917 |
- shall be a member of class `X` or be a member of a base class of `X` (
|
| 918 |
[[class.member.lookup]]), or
|
|
|
|
| 1039 |
### Argument-dependent name lookup <a id="basic.lookup.argdep">[[basic.lookup.argdep]]</a>
|
| 1040 |
|
| 1041 |
When the *postfix-expression* in a function call ([[expr.call]]) is an
|
| 1042 |
*unqualified-id*, other namespaces not considered during the usual
|
| 1043 |
unqualified lookup ([[basic.lookup.unqual]]) may be searched, and in
|
| 1044 |
+
those namespaces, namespace-scope friend function or function template
|
| 1045 |
+
declarations ([[class.friend]]) not otherwise visible may be found.
|
| 1046 |
+
These modifications to the search depend on the types of the arguments
|
| 1047 |
+
(and for template template arguments, the namespace of the template
|
| 1048 |
argument).
|
| 1049 |
|
| 1050 |
``` cpp
|
| 1051 |
namespace N {
|
| 1052 |
struct S { };
|
|
|
|
| 1073 |
- If `T` is a fundamental type, its associated sets of namespaces and
|
| 1074 |
classes are both empty.
|
| 1075 |
- If `T` is a class type (including unions), its associated classes are:
|
| 1076 |
the class itself; the class of which it is a member, if any; and its
|
| 1077 |
direct and indirect base classes. Its associated namespaces are the
|
| 1078 |
+
innermost enclosing namespaces of its associated classes. Furthermore,
|
| 1079 |
if `T` is a class template specialization, its associated namespaces
|
| 1080 |
and classes also include: the namespaces and classes associated with
|
| 1081 |
the types of the template arguments provided for template type
|
| 1082 |
parameters (excluding template template parameters); the namespaces of
|
| 1083 |
which any template template arguments are members; and the classes of
|
| 1084 |
which any member templates used as template template arguments are
|
| 1085 |
members. Non-type template arguments do not contribute to the set of
|
| 1086 |
associated namespaces.
|
| 1087 |
- If `T` is an enumeration type, its associated namespace is the
|
| 1088 |
+
innermost enclosing namespace of its declaration. If it is a class
|
| 1089 |
+
member, its associated class is the member’s class; else it has no
|
| 1090 |
+
associated class.
|
| 1091 |
- If `T` is a pointer to `U` or an array of `U`, its associated
|
| 1092 |
namespaces and classes are those associated with `U`.
|
| 1093 |
- If `T` is a function type, its associated namespaces and classes are
|
| 1094 |
those associated with the function parameter types and those
|
| 1095 |
associated with the return type.
|
|
|
|
| 1266 |
the context in which the entire *postfix-expression* occurs.
|
| 1267 |
- the lookup for a name specified in a *using-declaration* (
|
| 1268 |
[[namespace.udecl]]) also finds class or enumeration names hidden
|
| 1269 |
within the same scope ([[basic.scope.hiding]]).
|
| 1270 |
|
| 1271 |
+
In a lookup in which function names are not ignored[^9] and the
|
| 1272 |
+
*nested-name-specifier* nominates a class `C`:
|
| 1273 |
|
| 1274 |
- if the name specified after the *nested-name-specifier*, when looked
|
| 1275 |
up in `C`, is the injected-class-name of `C` (Clause [[class]]), or
|
| 1276 |
- in a *using-declaration* ([[namespace.udecl]]) that is a
|
| 1277 |
*member-declaration*, if the name specified after the
|
|
|
|
| 1607 |
*unqualified-id*, and the type of the object expression is of a class
|
| 1608 |
type `C`, the *unqualified-id* is looked up in the scope of class `C`.
|
| 1609 |
For a pseudo-destructor call ([[expr.pseudo]]), the *unqualified-id* is
|
| 1610 |
looked up in the context of the complete *postfix-expression*.
|
| 1611 |
|
| 1612 |
+
If the *unqualified-id* is `~`*type-name*, the *type-name* is looked up
|
| 1613 |
+
in the context of the entire *postfix-expression*. If the type `T` of
|
| 1614 |
+
the object expression is of a class type `C`, the *type-name* is also
|
| 1615 |
+
looked up in the scope of class `C`. At least one of the lookups shall
|
| 1616 |
+
find a name that refers to (possibly cv-qualified) `T`.
|
|
|
|
| 1617 |
|
| 1618 |
``` cpp
|
| 1619 |
struct A { };
|
| 1620 |
|
| 1621 |
struct B {
|
|
|
|
| 1701 |
A name having namespace scope ([[basic.scope.namespace]]) has internal
|
| 1702 |
linkage if it is the name of
|
| 1703 |
|
| 1704 |
- a variable, function or function template that is explicitly declared
|
| 1705 |
`static`; or,
|
| 1706 |
+
- a non-volatile variable that is explicitly declared `const` or
|
| 1707 |
+
`constexpr` and neither explicitly declared `extern` nor previously
|
| 1708 |
+
declared to have external linkage; or
|
| 1709 |
- a data member of an anonymous union.
|
| 1710 |
|
| 1711 |
An unnamed namespace or a namespace declared directly or indirectly
|
| 1712 |
within an unnamed namespace has internal linkage. All other namespaces
|
| 1713 |
have external linkage. A name having namespace scope that has not been
|
|
|
|
| 1782 |
|
| 1783 |
void q() { /* ... */ } // some other, unrelated q
|
| 1784 |
```
|
| 1785 |
|
| 1786 |
Names not covered by these rules have no linkage. Moreover, except as
|
| 1787 |
+
noted, a name declared at block scope ([[basic.scope.block]]) has no
|
| 1788 |
linkage. A type is said to have linkage if and only if:
|
| 1789 |
|
| 1790 |
- it is a class or enumeration type that is named (or has a name for
|
| 1791 |
linkage purposes ([[dcl.typedef]])) and the name has linkage; or
|
| 1792 |
- it is an unnamed class or enumeration member of a class with linkage;
|
| 1793 |
or
|
| 1794 |
+
- it is a specialization of a class template (Clause [[temp]])[^10]; or
|
| 1795 |
- it is a fundamental type ([[basic.fundamental]]); or
|
| 1796 |
- it is a compound type ([[basic.compound]]) other than a class or
|
| 1797 |
enumeration, compounded exclusively from types that have linkage; or
|
| 1798 |
- it is a cv-qualified ([[basic.type.qualifier]]) version of a type
|
| 1799 |
that has linkage.
|
|
|
|
| 1869 |
constructors for objects of namespace scope with static storage
|
| 1870 |
duration; termination contains the execution of destructors for objects
|
| 1871 |
with static storage duration.
|
| 1872 |
|
| 1873 |
An implementation shall not predefine the `main` function. This function
|
| 1874 |
+
shall not be overloaded. It shall have a declared return type of type
|
| 1875 |
+
`int`, but otherwise its type is *implementation-defined*. An
|
| 1876 |
+
implementation shall allow both
|
| 1877 |
|
| 1878 |
+
- a function of `()` returning `int` and
|
| 1879 |
+
- a function of `(int`, pointer to pointer to `char)` returning `int`
|
|
|
|
| 1880 |
|
| 1881 |
+
as the type of `main` ([[dcl.fct]]). In the latter form, for purposes
|
| 1882 |
+
of exposition, the first function parameter is called `argc` and the
|
| 1883 |
+
second function parameter is called `argv`, where `argc` shall be the
|
| 1884 |
+
number of arguments passed to the program from the environment in which
|
| 1885 |
+
the program is run. If `argc` is nonzero these arguments shall be
|
| 1886 |
+
supplied in `argv[0]` through `argv[argc-1]` as pointers to the initial
|
| 1887 |
+
characters of null-terminated multibyte strings (NTMBS s) (
|
| 1888 |
+
[[multibyte.strings]]) and `argv[0]` shall be the pointer to the initial
|
| 1889 |
+
character of a NTMBSthat represents the name used to invoke the program
|
| 1890 |
+
or `""`. The value of `argc` shall be non-negative. The value of
|
| 1891 |
+
`argv[argc]` shall be 0. It is recommended that any further (optional)
|
| 1892 |
+
parameters be added after `argv`.
|
|
|
|
|
|
|
|
|
|
| 1893 |
|
| 1894 |
The function `main` shall not be used within a program. The linkage (
|
| 1895 |
[[basic.link]]) of `main` is *implementation-defined*. A program that
|
| 1896 |
+
defines `main` as deleted or that declares `main` to be `inline`,
|
| 1897 |
`static`, or `constexpr` is ill-formed. The name `main` is not otherwise
|
| 1898 |
reserved. member functions, classes, and enumerations can be called
|
| 1899 |
`main`, as can entities in other namespaces.
|
| 1900 |
|
| 1901 |
Terminating the program without leaving the current block (e.g., by
|
|
|
|
| 1925 |
initialized as a consequence of thread execution. Within each of these
|
| 1926 |
phases of initiation, initialization occurs as follows.
|
| 1927 |
|
| 1928 |
Variables with static storage duration ([[basic.stc.static]]) or thread
|
| 1929 |
storage duration ([[basic.stc.thread]]) shall be zero-initialized (
|
| 1930 |
+
[[dcl.init]]) before any other initialization takes place. A *constant
|
| 1931 |
+
initializer* for an object `o` is an expression that is a constant
|
| 1932 |
+
expression, except that it may also invoke `constexpr` constructors for
|
| 1933 |
+
`o` and its subobjects even if those objects are of non-literal class
|
| 1934 |
+
types such a class may have a non-trivial destructor . *Constant
|
| 1935 |
+
initialization* is performed:
|
| 1936 |
|
| 1937 |
- if each full-expression (including implicit conversions) that appears
|
| 1938 |
in the initializer of a reference with static or thread storage
|
| 1939 |
duration is a constant expression ([[expr.const]]) and the reference
|
| 1940 |
is bound to an lvalue designating an object with static storage
|
| 1941 |
+
duration, to a temporary (see [[class.temporary]]), or to a function;
|
| 1942 |
- if an object with static or thread storage duration is initialized by
|
| 1943 |
+
a constructor call, and if the initialization full-expression is a
|
| 1944 |
+
constant initializer for the object;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1945 |
- if an object with static or thread storage duration is not initialized
|
| 1946 |
+
by a constructor call and if either the object is value-initialized or
|
| 1947 |
+
every full-expression that appears in its initializer is a constant
|
| 1948 |
+
expression.
|
| 1949 |
|
| 1950 |
Together, zero-initialization and constant initialization are called
|
| 1951 |
*static initialization*; all other initialization is *dynamic
|
| 1952 |
initialization*. Static initialization shall be performed before any
|
| 1953 |
dynamic initialization takes place. Dynamic initialization of a
|
|
|
|
| 2005 |
It is *implementation-defined* whether the dynamic initialization of a
|
| 2006 |
non-local variable with static storage duration is done before the first
|
| 2007 |
statement of `main`. If the initialization is deferred to some point in
|
| 2008 |
time after the first statement of `main`, it shall occur before the
|
| 2009 |
first odr-use ([[basic.def.odr]]) of any function or variable defined
|
| 2010 |
+
in the same translation unit as the variable to be initialized.[^11]
|
| 2011 |
|
| 2012 |
``` cpp
|
| 2013 |
// - File 1 -
|
| 2014 |
#include "a.h"
|
| 2015 |
#include "b.h"
|
|
|
|
| 2210 |
program.
|
| 2211 |
|
| 2212 |
``` cpp
|
| 2213 |
void* operator new(std::size_t);
|
| 2214 |
void* operator new[](std::size_t);
|
| 2215 |
+
void operator delete(void*) noexcept;
|
| 2216 |
+
void operator delete[](void*) noexcept;
|
| 2217 |
+
void operator delete(void*, std::size_t) noexcept;
|
| 2218 |
+
void operator delete[](void*, std::size_t) noexcept;
|
| 2219 |
```
|
| 2220 |
|
| 2221 |
These implicit declarations introduce only the function names `operator`
|
| 2222 |
`new`, `operator` `new[]`, `operator` `delete`, and `operator`
|
| 2223 |
`delete[]`. The implicit declarations do not introduce the names `std`,
|
|
|
|
| 2263 |
to a corresponding deallocation function). Even if the size of the space
|
| 2264 |
requested is zero, the request can fail. If the request succeeds, the
|
| 2265 |
value returned shall be a non-null pointer value ([[conv.ptr]]) `p0`
|
| 2266 |
different from any previously returned value `p1`, unless that value
|
| 2267 |
`p1` was subsequently passed to an `operator` `delete`. The effect of
|
| 2268 |
+
indirecting through a pointer returned as a request for zero size is
|
| 2269 |
+
undefined.[^12]
|
| 2270 |
|
| 2271 |
An allocation function that fails to allocate storage can invoke the
|
| 2272 |
currently installed new-handler function ([[new.handler]]), if any. A
|
| 2273 |
program-supplied allocation function can obtain the address of the
|
| 2274 |
currently installed `new_handler` using the `std::get_new_handler`
|
| 2275 |
function ([[set.new.handler]]). If an allocation function declared with
|
| 2276 |
a non-throwing *exception-specification* ([[except.spec]]) fails to
|
| 2277 |
allocate storage, it shall return a null pointer. Any other allocation
|
| 2278 |
function that fails to allocate storage shall indicate failure only by
|
| 2279 |
+
throwing an exception ([[except.throw]]) of a type that would match a
|
| 2280 |
+
handler ([[except.handle]]) of type `std::bad_alloc` ([[bad.alloc]]).
|
| 2281 |
|
| 2282 |
A global allocation function is only called as the result of a new
|
| 2283 |
expression ([[expr.new]]), or called directly using the function call
|
| 2284 |
syntax ([[expr.call]]), or called indirectly through calls to the
|
| 2285 |
functions in the C++standard library. In particular, a global allocation
|
| 2286 |
function is not called to allocate storage for objects with static
|
| 2287 |
storage duration ([[basic.stc.static]]), for objects or references with
|
| 2288 |
thread storage duration ([[basic.stc.thread]]), for objects of type
|
| 2289 |
+
`std::type_info` ([[expr.typeid]]), or for an exception object (
|
| 2290 |
+
[[except.throw]]).
|
| 2291 |
|
| 2292 |
#### Deallocation functions <a id="basic.stc.dynamic.deallocation">[[basic.stc.dynamic.deallocation]]</a>
|
| 2293 |
|
| 2294 |
Deallocation functions shall be class member functions or global
|
| 2295 |
functions; a program is ill-formed if deallocation functions are
|
| 2296 |
declared in a namespace scope other than global scope or declared static
|
| 2297 |
in global scope.
|
| 2298 |
|
| 2299 |
Each deallocation function shall return `void` and its first parameter
|
| 2300 |
shall be `void*`. A deallocation function can have more than one
|
| 2301 |
+
parameter. The global `operator delete` with exactly one parameter is a
|
| 2302 |
+
usual (non-placement) deallocation function. The global
|
| 2303 |
+
`operator delete` with exactly two parameters, the second of which has
|
| 2304 |
+
type `std::size_t`, is a usual deallocation function. Similarly, the
|
| 2305 |
+
global `operator delete[]` with exactly one parameter is a usual
|
| 2306 |
+
deallocation function. The global `operator delete[]` with exactly two
|
| 2307 |
+
parameters, the second of which has type `std::size_t`, is a usual
|
| 2308 |
+
deallocation function.[^13] If a class `T` has a member deallocation
|
| 2309 |
+
function named `operator` `delete` with exactly one parameter, then that
|
| 2310 |
+
function is a usual deallocation function. If class `T` does not declare
|
| 2311 |
+
such an `operator` `delete` but does declare a member deallocation
|
| 2312 |
+
function named `operator` `delete` with exactly two parameters, the
|
| 2313 |
+
second of which has type `std::size_t`, then this function is a usual
|
| 2314 |
+
deallocation function. Similarly, if a class `T` has a member
|
| 2315 |
+
deallocation function named `operator` `delete[]` with exactly one
|
| 2316 |
+
parameter, then that function is a usual (non-placement) deallocation
|
| 2317 |
+
function. If class `T` does not declare such an `operator` `delete[]`
|
| 2318 |
+
but does declare a member deallocation function named `operator`
|
| 2319 |
+
`delete[]` with exactly two parameters, the second of which has type
|
| 2320 |
+
`std::size_t`, then this function is a usual deallocation function. A
|
| 2321 |
+
deallocation function can be an instance of a function template. Neither
|
| 2322 |
+
the first parameter nor the return type shall depend on a template
|
| 2323 |
+
parameter. That is, a deallocation function template shall have a first
|
| 2324 |
+
parameter of type `void*` and a return type of `void` (as specified
|
| 2325 |
+
above). A deallocation function template shall have two or more function
|
| 2326 |
+
parameters. A template instance is never a usual deallocation function,
|
| 2327 |
+
regardless of its signature.
|
| 2328 |
|
| 2329 |
If a deallocation function terminates by throwing an exception, the
|
| 2330 |
behavior is undefined. The value of the first argument supplied to a
|
| 2331 |
deallocation function may be a null pointer value; if so, and if the
|
| 2332 |
deallocation function is one supplied in the standard library, the call
|
|
|
|
| 2342 |
|
| 2343 |
If the argument given to a deallocation function in the standard library
|
| 2344 |
is a pointer that is not the null pointer value ([[conv.ptr]]), the
|
| 2345 |
deallocation function shall deallocate the storage referenced by the
|
| 2346 |
pointer, rendering invalid all pointers referring to any part of the
|
| 2347 |
+
deallocated storage. Indirection through an invalid pointer value and
|
| 2348 |
+
passing an invalid pointer value to a deallocation function have
|
| 2349 |
+
undefined behavior. Any other use of an invalid pointer value has
|
| 2350 |
+
implementation-defined behavior.[^14]
|
| 2351 |
|
| 2352 |
#### Safely-derived pointers <a id="basic.stc.dynamic.safety">[[basic.stc.dynamic.safety]]</a>
|
| 2353 |
|
| 2354 |
A *traceable pointer object* is
|
| 2355 |
|
| 2356 |
- an object of an object pointer type ([[basic.compound]]), or
|
| 2357 |
- an object of an integral type that is at least as large as
|
| 2358 |
`std::intptr_t`, or
|
| 2359 |
+
- a sequence of elements in an array of narrow character type (
|
| 2360 |
+
[[basic.fundamental]]), where the size and alignment of the sequence
|
| 2361 |
+
match those of some object pointer type.
|
| 2362 |
|
| 2363 |
A pointer value is a *safely-derived pointer* to a dynamic object only
|
| 2364 |
if it has an object pointer type and it is one of the following:
|
| 2365 |
|
| 2366 |
- the value returned by a call to the C++standard library implementation
|
| 2367 |
+
of `::operator new(std::size_t)`;[^15]
|
| 2368 |
- the result of taking the address of an object (or one of its
|
| 2369 |
+
subobjects) designated by an lvalue resulting from indirection through
|
| 2370 |
+
a safely-derived pointer value;
|
| 2371 |
- the result of well-defined pointer arithmetic ([[expr.add]]) using a
|
| 2372 |
safely-derived pointer value;
|
| 2373 |
- the result of a well-defined pointer conversion ([[conv.ptr]],
|
| 2374 |
[[expr.cast]]) of a safely-derived pointer value;
|
| 2375 |
- the result of a `reinterpret_cast` of a safely-derived pointer value;
|
|
|
|
| 2396 |
`reinterpret_cast<void*>(P)`.
|
| 2397 |
|
| 2398 |
An implementation may have *relaxed pointer safety*, in which case the
|
| 2399 |
validity of a pointer value does not depend on whether it is a
|
| 2400 |
safely-derived pointer value. Alternatively, an implementation may have
|
| 2401 |
+
*strict pointer safety*, in which case a pointer value referring to an
|
| 2402 |
+
object with dynamic storage duration that is not a safely-derived
|
| 2403 |
+
pointer value is an invalid pointer value unless the referenced complete
|
| 2404 |
+
object has previously been declared reachable (
|
| 2405 |
+
[[util.dynamic.safety]]). the effect of using an invalid pointer value
|
| 2406 |
+
(including passing it to a deallocation function) is undefined, see
|
| 2407 |
[[basic.stc.dynamic.deallocation]]. This is true even if the
|
| 2408 |
unsafely-derived pointer value might compare equal to some
|
| 2409 |
safely-derived pointer value. It is implementation defined whether an
|
| 2410 |
implementation has relaxed or strict pointer safety.
|
| 2411 |
|
|
|
|
| 2460 |
used to release the storage, the destructor shall not be implicitly
|
| 2461 |
called and any program that depends on the side effects produced by the
|
| 2462 |
destructor has undefined behavior.
|
| 2463 |
|
| 2464 |
Before the lifetime of an object has started but after the storage which
|
| 2465 |
+
the object will occupy has been allocated[^16] or, after the lifetime of
|
| 2466 |
an object has ended and before the storage which the object occupied is
|
| 2467 |
reused or released, any pointer that refers to the storage location
|
| 2468 |
where the object will be or was located may be used but only in limited
|
| 2469 |
ways. For an object under construction or destruction, see
|
| 2470 |
[[class.cdtor]]. Otherwise, such a pointer refers to allocated storage (
|
| 2471 |
[[basic.stc.dynamic.deallocation]]), and using the pointer as if the
|
| 2472 |
+
pointer were of type `void*`, is well-defined. Indirection through such
|
| 2473 |
+
a pointer is permitted but the resulting lvalue may only be used in
|
| 2474 |
+
limited ways, as described below. The program has undefined behavior if:
|
| 2475 |
|
| 2476 |
- the object will be or was of a class type with a non-trivial
|
| 2477 |
destructor and the pointer is used as the operand of a
|
| 2478 |
*delete-expression*,
|
| 2479 |
- the pointer is used to access a non-static data member or call a
|
| 2480 |
non-static member function of the object, or
|
| 2481 |
- the pointer is implicitly converted ([[conv.ptr]]) to a pointer to a
|
| 2482 |
+
virtual base class, or
|
| 2483 |
- the pointer is used as the operand of a `static_cast` (
|
| 2484 |
+
[[expr.static.cast]]), except when the conversion is to pointer to
|
| 2485 |
+
*cv* `void`, or to pointer to *cv* `void` and subsequently to pointer
|
| 2486 |
+
to either *cv* `char` or *cv* `unsigned char`, or
|
| 2487 |
- the pointer is used as the operand of a `dynamic_cast` (
|
| 2488 |
[[expr.dynamic.cast]]).
|
| 2489 |
``` cpp
|
| 2490 |
#include <cstdlib>
|
| 2491 |
|
|
|
|
| 2527 |
|
| 2528 |
- an lvalue-to-rvalue conversion ([[conv.lval]]) is applied to such a
|
| 2529 |
glvalue,
|
| 2530 |
- the glvalue is used to access a non-static data member or call a
|
| 2531 |
non-static member function of the object, or
|
| 2532 |
+
- the glvalue is bound to a reference to a virtual base class (
|
| 2533 |
+
[[dcl.init.ref]]), or
|
|
|
|
|
|
|
|
|
|
| 2534 |
- the glvalue is used as the operand of a `dynamic_cast` (
|
| 2535 |
[[expr.dynamic.cast]]) or as the operand of `typeid`.
|
| 2536 |
|
| 2537 |
If, after the lifetime of an object has ended and before the storage
|
| 2538 |
which the object occupied is reused or released, a new object is created
|
|
|
|
| 2575 |
```
|
| 2576 |
|
| 2577 |
If a program ends the lifetime of an object of type `T` with static (
|
| 2578 |
[[basic.stc.static]]), thread ([[basic.stc.thread]]), or automatic (
|
| 2579 |
[[basic.stc.auto]]) storage duration and if `T` has a non-trivial
|
| 2580 |
+
destructor,[^17] the program must ensure that an object of the original
|
| 2581 |
type occupies that same storage location when the implicit destructor
|
| 2582 |
call takes place; otherwise the behavior of the program is undefined.
|
| 2583 |
This is true even if the block is exited with an exception.
|
| 2584 |
|
| 2585 |
``` cpp
|
|
|
|
| 2627 |
[[dcl.fct]]).
|
| 2628 |
|
| 2629 |
For any object (other than a base-class subobject) of trivially copyable
|
| 2630 |
type `T`, whether or not the object holds a valid value of type `T`, the
|
| 2631 |
underlying bytes ([[intro.memory]]) making up the object can be copied
|
| 2632 |
+
into an array of `char` or `unsigned` `char`.[^18] If the content of the
|
| 2633 |
array of `char` or `unsigned` `char` is copied back into the object, the
|
| 2634 |
object shall subsequently hold its original value.
|
| 2635 |
|
| 2636 |
``` cpp
|
| 2637 |
#define N sizeof(T)
|
|
|
|
| 2644 |
```
|
| 2645 |
|
| 2646 |
For any trivially copyable type `T`, if two pointers to `T` point to
|
| 2647 |
distinct `T` objects `obj1` and `obj2`, where neither `obj1` nor `obj2`
|
| 2648 |
is a base-class subobject, if the underlying bytes ([[intro.memory]])
|
| 2649 |
+
making up `obj1` are copied into `obj2`,[^19] `obj2` shall subsequently
|
| 2650 |
hold the same value as `obj1`.
|
| 2651 |
|
| 2652 |
``` cpp
|
| 2653 |
T* t1p;
|
| 2654 |
T* t2p;
|
|
|
|
| 2662 |
*N* `unsigned` `char` objects taken up by the object of type `T`, where
|
| 2663 |
*N* equals `sizeof(T)`. The *value representation* of an object is the
|
| 2664 |
set of bits that hold the value of type `T`. For trivially copyable
|
| 2665 |
types, the value representation is a set of bits in the object
|
| 2666 |
representation that determines a *value*, which is one discrete element
|
| 2667 |
+
of an *implementation-defined* set of values.[^20]
|
| 2668 |
|
| 2669 |
+
A class that has been declared but not defined, an enumeration type in
|
| 2670 |
+
certain contexts ([[dcl.enum]]), or an array of unknown size or of
|
| 2671 |
+
incomplete element type, is an *incompletely-defined object type*.[^21]
|
| 2672 |
+
Incompletely-defined object types and the void types are *incomplete
|
| 2673 |
+
types* ([[basic.fundamental]]). Objects shall not be defined to have an
|
| 2674 |
+
incomplete type.
|
| 2675 |
|
| 2676 |
A class type (such as “`class X`”) might be incomplete at one point in a
|
| 2677 |
translation unit and complete later on; the type “`class X`” is the same
|
| 2678 |
type at both points. The declared type of an array object might be an
|
| 2679 |
array of incomplete class type and therefore incomplete; if the class
|
| 2680 |
type is completed later on in the translation unit, the array type
|
| 2681 |
becomes complete; the array type at those two points is the same type.
|
| 2682 |
The declared type of an array object might be an array of unknown size
|
| 2683 |
and therefore be incomplete at one point in a translation unit and
|
| 2684 |
complete later on; the array types at those two points (“array of
|
| 2685 |
+
unknown bound of `T`” and “array of `N` `T`”) are different types. The
|
| 2686 |
type of a pointer to array of unknown size, or of a type defined by a
|
| 2687 |
`typedef` declaration to be an array of unknown size, cannot be
|
| 2688 |
completed.
|
| 2689 |
|
| 2690 |
``` cpp
|
|
|
|
| 2723 |
types, pointer to member types ([[basic.compound]]), `std::nullptr_t`,
|
| 2724 |
and cv-qualified versions of these types ([[basic.type.qualifier]]) are
|
| 2725 |
collectively called *scalar types*. Scalar types, POD classes (Clause
|
| 2726 |
[[class]]), arrays of such types and *cv-qualified* versions of these
|
| 2727 |
types ([[basic.type.qualifier]]) are collectively called *POD types*.
|
| 2728 |
+
Cv-unqualified scalar types, trivially copyable class types (Clause
|
| 2729 |
+
[[class]]), arrays of such types, and non-volatile const-qualified
|
| 2730 |
+
versions of these types ([[basic.type.qualifier]]) are collectively
|
| 2731 |
+
called *trivially copyable types*. Scalar types, trivial class types
|
| 2732 |
+
(Clause [[class]]), arrays of such types and cv-qualified versions of
|
| 2733 |
+
these types ([[basic.type.qualifier]]) are collectively called *trivial
|
| 2734 |
+
types*. Scalar types, standard-layout class types (Clause [[class]]),
|
| 2735 |
+
arrays of such types and cv-qualified versions of these types (
|
| 2736 |
[[basic.type.qualifier]]) are collectively called *standard-layout
|
| 2737 |
types*.
|
| 2738 |
|
| 2739 |
A type is a *literal type* if it is:
|
| 2740 |
|
| 2741 |
+
- `void`; or
|
| 2742 |
- a scalar type; or
|
| 2743 |
+
- a reference type; or
|
| 2744 |
- an array of literal type; or
|
| 2745 |
- a class type (Clause [[class]]) that has all of the following
|
| 2746 |
properties:
|
| 2747 |
- it has a trivial destructor,
|
|
|
|
|
|
|
|
|
|
| 2748 |
- it is an aggregate type ([[dcl.init.aggr]]) or has at least one
|
| 2749 |
`constexpr` constructor or constructor template that is not a copy
|
| 2750 |
or move constructor, and
|
| 2751 |
+
- all of its non-static data members and base classes are of
|
| 2752 |
+
non-volatile literal types.
|
| 2753 |
|
| 2754 |
If two types `T1` and `T2` are the same type, then `T1` and `T2` are
|
| 2755 |
*layout-compatible* types. Layout-compatible enumerations are described
|
| 2756 |
in [[dcl.enum]]. Layout-compatible standard-layout structs and
|
| 2757 |
standard-layout unions are described in [[class.mem]].
|
|
|
|
| 2763 |
from this set is stored in a character object, the integral value of
|
| 2764 |
that character object is equal to the value of the single character
|
| 2765 |
literal form of that character. It is *implementation-defined* whether a
|
| 2766 |
`char` object can hold negative values. Characters can be explicitly
|
| 2767 |
declared `unsigned` or `signed`. Plain `char`, `signed char`, and
|
| 2768 |
+
`unsigned char` are three distinct types, collectively called *narrow
|
| 2769 |
+
character types*. A `char`, a `signed char`, and an `unsigned char`
|
| 2770 |
+
occupy the same amount of storage and have the same alignment
|
| 2771 |
+
requirements ([[basic.align]]); that is, they have the same object
|
| 2772 |
+
representation. For narrow character types, all bits of the object
|
| 2773 |
representation participate in the value representation. For unsigned
|
| 2774 |
+
narrow character types, all possible bit patterns of the value
|
| 2775 |
+
representation represent numbers. These requirements do not hold for
|
| 2776 |
+
other types. In any particular implementation, a plain `char` object can
|
| 2777 |
+
take on either the same values as a `signed char` or an `unsigned
|
| 2778 |
+
char`; which one is *implementation-defined*. For each value *i* of type
|
| 2779 |
+
`unsigned char` in the range 0 to 255 inclusive, there exists a value
|
| 2780 |
+
*j* of type `char` such that the result of an integral conversion (
|
| 2781 |
+
[[conv.integral]]) from *i* to `char` is *j*, and the result of an
|
| 2782 |
+
integral conversion from *j* to `unsigned char` is *i*.
|
| 2783 |
|
| 2784 |
There are five *standard signed integer types* : “`signed char`”,
|
| 2785 |
“`short int`”, “`int`”, “`long int`”, and “`long` `long` `int`”. In this
|
| 2786 |
list, each type provides at least as much storage as those preceding it
|
| 2787 |
in the list. There may also be *implementation-defined* *extended signed
|
| 2788 |
integer types*. The standard and extended signed integer types are
|
| 2789 |
collectively called *signed integer types*. Plain `int`s have the
|
| 2790 |
natural size suggested by the architecture of the execution
|
| 2791 |
+
environment[^22]; the other signed integer types are provided to meet
|
| 2792 |
special needs.
|
| 2793 |
|
| 2794 |
For each of the standard signed integer types, there exists a
|
| 2795 |
corresponding (but different) *standard unsigned integer type*:
|
| 2796 |
“`unsigned char`”, “`unsigned short int`”, “`unsigned int`”,
|
| 2797 |
“`unsigned long int`”, and “`unsigned` `long` `long` `int`”, each of
|
| 2798 |
which occupies the same amount of storage and has the same alignment
|
| 2799 |
requirements ([[basic.align]]) as the corresponding signed integer
|
| 2800 |
+
type[^23]; that is, each signed integer type has the same object
|
| 2801 |
representation as its corresponding unsigned integer type. Likewise, for
|
| 2802 |
each of the extended signed integer types there exists a corresponding
|
| 2803 |
*extended unsigned integer type* with the same amount of storage and
|
| 2804 |
alignment requirements. The standard and extended unsigned integer types
|
| 2805 |
are collectively called *unsigned integer types*. The range of
|
|
|
|
| 2807 |
corresponding *unsigned integer* type, and the value representation of
|
| 2808 |
each corresponding signed/unsigned type shall be the same. The standard
|
| 2809 |
signed integer types and standard unsigned integer types are
|
| 2810 |
collectively called the *standard integer types*, and the extended
|
| 2811 |
signed integer types and extended unsigned integer types are
|
| 2812 |
+
collectively called the *extended integer types*. The signed and
|
| 2813 |
+
unsigned integer types shall satisfy the constraints given in the C
|
| 2814 |
+
standard, section 5.2.4.2.1.
|
| 2815 |
|
| 2816 |
+
Unsigned integers shall obey the laws of arithmetic modulo 2ⁿ where n is
|
| 2817 |
+
the number of bits in the value representation of that particular size
|
| 2818 |
+
of integer.[^24]
|
| 2819 |
|
| 2820 |
Type `wchar_t` is a distinct type whose values can represent distinct
|
| 2821 |
codes for all members of the largest extended character set specified
|
| 2822 |
among the supported locales ([[locale]]). Type `wchar_t` shall have the
|
| 2823 |
same size, signedness, and alignment requirements ([[basic.align]]) as
|
| 2824 |
one of the other integral types, called its *underlying type*. Types
|
| 2825 |
`char16_t` and `char32_t` denote distinct types with the same size,
|
| 2826 |
signedness, and alignment as `uint_least16_t` and `uint_least32_t`,
|
| 2827 |
+
respectively, in `<cstdint>`, called the underlying types.
|
| 2828 |
|
| 2829 |
+
Values of type `bool` are either `true` or `false`.[^25] There are no
|
| 2830 |
`signed`, `unsigned`, `short`, or `long bool` types or values. Values of
|
| 2831 |
type `bool` participate in integral promotions ([[conv.prom]]).
|
| 2832 |
|
| 2833 |
Types `bool`, `char`, `char16_t`, `char32_t`, `wchar_t`, and the signed
|
| 2834 |
and unsigned integer types are collectively called *integral*
|
| 2835 |
+
types.[^26] A synonym for integral type is *integer type*. The
|
| 2836 |
representations of integral types shall define values by use of a pure
|
| 2837 |
+
binary numeration system.[^27] this International Standard permits 2’s
|
| 2838 |
complement, 1’s complement and signed magnitude representations for
|
| 2839 |
integral types.
|
| 2840 |
|
| 2841 |
There are three *floating point* types: `float`, `double`, and
|
| 2842 |
`long double`. The type `double` provides at least as much precision as
|
|
|
|
| 2856 |
for functions that do not return a value. Any expression can be
|
| 2857 |
explicitly converted to type *cv* `void` ([[expr.cast]]). An expression
|
| 2858 |
of type `void` shall be used only as an expression statement (
|
| 2859 |
[[stmt.expr]]), as an operand of a comma expression ([[expr.comma]]),
|
| 2860 |
as a second or third operand of `?:` ([[expr.cond]]), as the operand of
|
| 2861 |
+
`typeid`, `noexcept`, or `decltype`, as the expression in a return
|
| 2862 |
+
statement ([[stmt.return]]) for a function with the return type `void`,
|
| 2863 |
+
or as the operand of an explicit conversion to type cv `void`.
|
| 2864 |
|
| 2865 |
A value of type `std::nullptr_t` is a null pointer constant (
|
| 2866 |
[[conv.ptr]]). Such values participate in the pointer and the pointer to
|
| 2867 |
member conversions ([[conv.ptr]], [[conv.mem]]).
|
| 2868 |
`sizeof(std::nullptr_t)` shall be equal to `sizeof(void*)`.
|
|
|
|
| 2891 |
- *unions*, which are classes capable of containing objects of different
|
| 2892 |
types at different times, [[class.union]];
|
| 2893 |
- *enumerations*, which comprise a set of named constant values. Each
|
| 2894 |
distinct enumeration constitutes a different *enumerated type*,
|
| 2895 |
[[dcl.enum]];
|
| 2896 |
+
- *pointers to non-static* [^28] *class members*, which identify members
|
| 2897 |
of a given type within objects of a given class, [[dcl.mptr]].
|
| 2898 |
|
| 2899 |
These methods of constructing types can be applied recursively;
|
| 2900 |
restrictions are mentioned in [[dcl.ptr]], [[dcl.array]], [[dcl.fct]],
|
| 2901 |
+
and [[dcl.ref]]. Constructing a type such that the number of bytes in
|
| 2902 |
+
its object representation exceeds the maximum value representable in the
|
| 2903 |
+
type `std::size_t` ([[support.types]]) is ill-formed.
|
| 2904 |
|
| 2905 |
The type of a pointer to `void` or a pointer to an object type is called
|
| 2906 |
an *object pointer type*. A pointer to `void` does not have a
|
| 2907 |
pointer-to-object type, however, because `void` is not an object type.
|
| 2908 |
The type of a pointer that can designate a function is called a
|
|
|
|
| 2946 |
*cv-unqualified type*. Each type which is a cv-unqualified complete or
|
| 2947 |
incomplete object type or is `void` ([[basic.types]]) has three
|
| 2948 |
corresponding cv-qualified versions of its type: a *const-qualified*
|
| 2949 |
version, a *volatile-qualified* version, and a
|
| 2950 |
*const-volatile-qualified* version. The term *object type* (
|
| 2951 |
+
[[intro.object]]) includes the cv-qualifiers specified in the
|
| 2952 |
+
*decl-specifier-seq* ([[dcl.spec]]), *declarator* (Clause
|
| 2953 |
+
[[dcl.decl]]), *type-id* ([[dcl.name]]), or *new-type-id* (
|
| 2954 |
+
[[expr.new]]) when the object is created.
|
| 2955 |
+
|
| 2956 |
+
- A *const object* is an object of type `const T` or a non-mutable
|
| 2957 |
+
subobject of such an object.
|
| 2958 |
+
- A *volatile object* is an object of type `volatile T`, a subobject of
|
| 2959 |
+
such an object, or a mutable subobject of a const volatile object.
|
| 2960 |
+
- A *const volatile object* is an object of type `const volatile T`, a
|
| 2961 |
+
non-mutable subobject of such an object, a const subobject of a
|
| 2962 |
+
volatile object, or a non-mutable volatile subobject of a const
|
| 2963 |
+
object.
|
| 2964 |
+
|
| 2965 |
+
The cv-qualified or cv-unqualified versions of a type are distinct
|
| 2966 |
+
types; however, they shall have the same representation and alignment
|
| 2967 |
+
requirements ([[basic.align]]).[^29]
|
| 2968 |
|
| 2969 |
A compound type ([[basic.compound]]) is not cv-qualified by the
|
| 2970 |
cv-qualifiers (if any) of the types from which it is compounded. Any
|
| 2971 |
cv-qualifiers applied to an array type affect the array element type,
|
| 2972 |
not the array type ([[dcl.array]]).
|
| 2973 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2974 |
See [[dcl.fct]] and [[class.this]] regarding function types that have
|
| 2975 |
*cv-qualifier*s.
|
| 2976 |
|
| 2977 |
There is a partial ordering on cv-qualifiers, so that a type can be said
|
| 2978 |
to be *more cv-qualified* than another. Table
|
|
|
|
| 2994 |
etc.), used in the description of types, represents an arbitrary set of
|
| 2995 |
cv-qualifiers, i.e., one of {`const`}, {`volatile`}, {`const`,
|
| 2996 |
`volatile`}, or the empty set. Cv-qualifiers applied to an array type
|
| 2997 |
attach to the underlying element type, so the notation “*cv* `T`,” where
|
| 2998 |
`T` is an array type, refers to an array whose elements are
|
| 2999 |
+
so-qualified. An array type whose elements are cv-qualified is also
|
| 3000 |
+
considered to have the same cv-qualifications as its elements.
|
| 3001 |
+
|
| 3002 |
+
``` cpp
|
| 3003 |
+
typedef char CA[5];
|
| 3004 |
+
typedef const char CC;
|
| 3005 |
+
CC arr1[5] = { 0 };
|
| 3006 |
+
const CA arr2 = { 0 };
|
| 3007 |
+
```
|
| 3008 |
+
|
| 3009 |
+
The type of both `arr1` and `arr2` is “array of 5 `const char`,” and the
|
| 3010 |
+
array type is considered to be `const`-qualified.
|
| 3011 |
|
| 3012 |
## Lvalues and rvalues <a id="basic.lval">[[basic.lval]]</a>
|
| 3013 |
|
| 3014 |
Expressions are categorized according to the taxonomy in Figure
|
| 3015 |
[[fig:categories]].
|
|
|
|
| 3026 |
return type is an lvalue reference is an lvalue.
|
| 3027 |
- An *xvalue* (an “eXpiring” value) also refers to an object, usually
|
| 3028 |
near the end of its lifetime (so that its resources may be moved, for
|
| 3029 |
example). An xvalue is the result of certain kinds of expressions
|
| 3030 |
involving rvalue references ([[dcl.ref]]). The result of calling a
|
| 3031 |
+
function whose return type is an rvalue reference to an object type is
|
| 3032 |
+
an xvalue ([[expr.call]]).
|
| 3033 |
- A *glvalue* (“generalized” lvalue) is an lvalue or an xvalue.
|
| 3034 |
- An *rvalue* (so called, historically, because rvalues could appear on
|
| 3035 |
the right-hand side of an assignment expression) is an xvalue, a
|
| 3036 |
temporary object ([[class.temporary]]) or subobject thereof, or a
|
| 3037 |
value that is not associated with an object.
|
|
|
|
| 3058 |
|
| 3059 |
The discussion of reference initialization in [[dcl.init.ref]] and of
|
| 3060 |
temporaries in [[class.temporary]] indicates the behavior of lvalues
|
| 3061 |
and rvalues in other significant contexts.
|
| 3062 |
|
| 3063 |
+
Unless otherwise indicated ([[expr.call]]), prvalues shall always have
|
| 3064 |
+
complete types or the `void` type; in addition to these types, glvalues
|
| 3065 |
+
can also have incomplete types. class and array prvalues can have
|
| 3066 |
+
cv-qualified types; other prvalues always have cv-unqualified types. See
|
| 3067 |
+
Clause [[expr]].
|
| 3068 |
|
| 3069 |
An lvalue for an object is necessary in order to modify the object
|
| 3070 |
except that an rvalue of class type can also be used to modify its
|
| 3071 |
referent under certain circumstances. a member function called for an
|
| 3072 |
object ([[class.mfct]]) can modify the object.
|
|
|
|
| 3087 |
an object through a nonmodifiable lvalue or rvalue expression is
|
| 3088 |
ill-formed.
|
| 3089 |
|
| 3090 |
If a program attempts to access the stored value of an object through a
|
| 3091 |
glvalue of other than one of the following types the behavior is
|
| 3092 |
+
undefined:[^30]
|
| 3093 |
|
| 3094 |
- the dynamic type of the object,
|
| 3095 |
- a cv-qualified version of the dynamic type of the object,
|
| 3096 |
- a type similar (as defined in [[conv.qual]]) to the dynamic type of
|
| 3097 |
the object,
|
|
|
|
| 3156 |
alignments. Stricter alignments have larger alignment values. An address
|
| 3157 |
that satisfies an alignment requirement also satisfies any weaker valid
|
| 3158 |
alignment requirement.
|
| 3159 |
|
| 3160 |
The alignment requirement of a complete type can be queried using an
|
| 3161 |
+
`alignof` expression ([[expr.alignof]]). Furthermore, the narrow
|
| 3162 |
+
character types ([[basic.fundamental]]) shall have the weakest
|
| 3163 |
+
alignment requirement. This enables the narrow character types to be
|
| 3164 |
+
used as the underlying type for an aligned memory area ([[dcl.align]]).
|
| 3165 |
|
| 3166 |
Comparing alignments is meaningful and provides the obvious results:
|
| 3167 |
|
| 3168 |
- Two alignments are equal when their numeric values are equal.
|
| 3169 |
- Two alignments are different when their numeric values are not equal.
|
|
|
|
| 3200 |
[basic.lookup.udir]: #basic.lookup.udir
|
| 3201 |
[basic.lookup.unqual]: #basic.lookup.unqual
|
| 3202 |
[basic.lval]: #basic.lval
|
| 3203 |
[basic.namespace]: dcl.md#basic.namespace
|
| 3204 |
[basic.scope]: #basic.scope
|
| 3205 |
+
[basic.scope.block]: #basic.scope.block
|
| 3206 |
[basic.scope.class]: #basic.scope.class
|
| 3207 |
[basic.scope.declarative]: #basic.scope.declarative
|
| 3208 |
[basic.scope.enum]: #basic.scope.enum
|
| 3209 |
[basic.scope.hiding]: #basic.scope.hiding
|
|
|
|
| 3210 |
[basic.scope.namespace]: #basic.scope.namespace
|
| 3211 |
[basic.scope.pdecl]: #basic.scope.pdecl
|
| 3212 |
[basic.scope.proto]: #basic.scope.proto
|
| 3213 |
[basic.scope.temp]: #basic.scope.temp
|
| 3214 |
[basic.start]: #basic.start
|
|
|
|
| 3251 |
[class.this]: class.md#class.this
|
| 3252 |
[class.union]: class.md#class.union
|
| 3253 |
[conv]: conv.md#conv
|
| 3254 |
[conv.array]: conv.md#conv.array
|
| 3255 |
[conv.func]: conv.md#conv.func
|
| 3256 |
+
[conv.integral]: conv.md#conv.integral
|
| 3257 |
[conv.lval]: conv.md#conv.lval
|
| 3258 |
[conv.mem]: conv.md#conv.mem
|
| 3259 |
[conv.prom]: conv.md#conv.prom
|
| 3260 |
[conv.ptr]: conv.md#conv.ptr
|
| 3261 |
[conv.qual]: conv.md#conv.qual
|
| 3262 |
[dcl.align]: dcl.md#dcl.align
|
| 3263 |
[dcl.array]: dcl.md#dcl.array
|
|
|
|
| 3264 |
[dcl.dcl]: dcl.md#dcl.dcl
|
| 3265 |
[dcl.decl]: dcl.md#dcl.decl
|
| 3266 |
[dcl.enum]: dcl.md#dcl.enum
|
| 3267 |
[dcl.fct]: dcl.md#dcl.fct
|
| 3268 |
[dcl.fct.def]: dcl.md#dcl.fct.def
|
|
|
|
| 3271 |
[dcl.init]: dcl.md#dcl.init
|
| 3272 |
[dcl.init.aggr]: dcl.md#dcl.init.aggr
|
| 3273 |
[dcl.init.ref]: dcl.md#dcl.init.ref
|
| 3274 |
[dcl.link]: dcl.md#dcl.link
|
| 3275 |
[dcl.mptr]: dcl.md#dcl.mptr
|
| 3276 |
+
[dcl.name]: dcl.md#dcl.name
|
| 3277 |
[dcl.ptr]: dcl.md#dcl.ptr
|
| 3278 |
[dcl.ref]: dcl.md#dcl.ref
|
| 3279 |
+
[dcl.spec]: dcl.md#dcl.spec
|
| 3280 |
[dcl.stc]: dcl.md#dcl.stc
|
| 3281 |
[dcl.type.cv]: dcl.md#dcl.type.cv
|
| 3282 |
[dcl.type.elab]: dcl.md#dcl.type.elab
|
| 3283 |
[dcl.type.simple]: dcl.md#dcl.type.simple
|
| 3284 |
[dcl.typedef]: dcl.md#dcl.typedef
|
| 3285 |
+
[diff.cpp11.basic]: compatibility.md#diff.cpp11.basic
|
| 3286 |
[except]: except.md#except
|
| 3287 |
[except.handle]: except.md#except.handle
|
| 3288 |
[except.spec]: except.md#except.spec
|
| 3289 |
[except.terminate]: except.md#except.terminate
|
| 3290 |
[except.throw]: except.md#except.throw
|
|
|
|
| 3297 |
[expr.comma]: expr.md#expr.comma
|
| 3298 |
[expr.cond]: expr.md#expr.cond
|
| 3299 |
[expr.const]: expr.md#expr.const
|
| 3300 |
[expr.delete]: expr.md#expr.delete
|
| 3301 |
[expr.dynamic.cast]: expr.md#expr.dynamic.cast
|
| 3302 |
+
[expr.mptr.oper]: expr.md#expr.mptr.oper
|
| 3303 |
[expr.new]: expr.md#expr.new
|
| 3304 |
[expr.prim]: expr.md#expr.prim
|
| 3305 |
+
[expr.prim.general]: expr.md#expr.prim.general
|
| 3306 |
[expr.pseudo]: expr.md#expr.pseudo
|
| 3307 |
[expr.ref]: expr.md#expr.ref
|
| 3308 |
[expr.sizeof]: expr.md#expr.sizeof
|
| 3309 |
[expr.static.cast]: expr.md#expr.static.cast
|
| 3310 |
[expr.type.conv]: expr.md#expr.type.conv
|
|
|
|
| 3331 |
[over]: over.md#over
|
| 3332 |
[over.literal]: over.md#over.literal
|
| 3333 |
[over.load]: over.md#over.load
|
| 3334 |
[over.match]: over.md#over.match
|
| 3335 |
[over.oper]: over.md#over.oper
|
| 3336 |
+
[over.over]: over.md#over.over
|
| 3337 |
[ptr.align]: utilities.md#ptr.align
|
| 3338 |
[replacement.functions]: library.md#replacement.functions
|
| 3339 |
[set.new.handler]: language.md#set.new.handler
|
| 3340 |
[stmt.block]: stmt.md#stmt.block
|
| 3341 |
[stmt.dcl]: stmt.md#stmt.dcl
|
|
|
|
| 3394 |
[^6]: This lookup applies whether the definition of `X` is nested within
|
| 3395 |
`Y`’s definition or whether `X`’s definition appears in a namespace
|
| 3396 |
scope enclosing `Y` ’s definition ([[class.nest]]).
|
| 3397 |
|
| 3398 |
[^7]: That is, an unqualified name that occurs, for instance, in a type
|
| 3399 |
+
in the *parameter-declaration-clause* or in the
|
| 3400 |
+
*exception-specification*.
|
| 3401 |
|
| 3402 |
[^8]: This lookup applies whether the member function is defined within
|
| 3403 |
the definition of class `X` or whether the member function is
|
| 3404 |
defined in a namespace scope enclosing `X`’s definition.
|
| 3405 |
|
| 3406 |
+
[^9]: Lookups in which function names are ignored include names
|
| 3407 |
+
appearing in a *nested-name-specifier*, an
|
| 3408 |
+
*elaborated-type-specifier*, or a *base-specifier*.
|
| 3409 |
|
| 3410 |
+
[^10]: A class template always has external linkage, and the
|
| 3411 |
+
requirements of [[temp.arg.type]] and [[temp.arg.nontype]] ensure
|
| 3412 |
+
that the template arguments will also have appropriate linkage.
|
| 3413 |
+
|
| 3414 |
+
[^11]: A non-local variable with static storage duration having
|
| 3415 |
initialization with side-effects must be initialized even if it is
|
| 3416 |
not odr-used ([[basic.def.odr]], [[basic.stc.static]]).
|
| 3417 |
|
| 3418 |
+
[^12]: The intent is to have `operator new()` implementable by calling
|
| 3419 |
`std::malloc()` or `std::calloc()`, so the rules are substantially
|
| 3420 |
the same. C++differs from C in requiring a zero request to return a
|
| 3421 |
non-null pointer.
|
| 3422 |
|
| 3423 |
+
[^13]: This deallocation function precludes use of an allocation
|
| 3424 |
+
function `void operator new(std::size_t, std::size_t)` as a
|
| 3425 |
+
placement allocation function ([[diff.cpp11.basic]]).
|
| 3426 |
|
| 3427 |
+
[^14]: Some implementations might define that copying an invalid pointer
|
| 3428 |
+
value causes a system-generated runtime fault.
|
| 3429 |
+
|
| 3430 |
+
[^15]: This section does not impose restrictions on indirection through
|
| 3431 |
pointers to memory not allocated by `::operator new`. This maintains
|
| 3432 |
the ability of many C++implementations to use binary libraries and
|
| 3433 |
components written in other languages. In particular, this applies
|
| 3434 |
+
to C binaries, because indirection through pointers to memory
|
| 3435 |
+
allocated by `std::malloc` is not restricted.
|
| 3436 |
|
| 3437 |
+
[^16]: For example, before the construction of a global object of
|
| 3438 |
non-POD class type ([[class.cdtor]]).
|
| 3439 |
|
| 3440 |
+
[^17]: That is, an object for which a destructor will be called
|
| 3441 |
implicitly—upon exit from the block for an object with automatic
|
| 3442 |
storage duration, upon exit from the thread for an object with
|
| 3443 |
thread storage duration, or upon exit from the program for an object
|
| 3444 |
with static storage duration.
|
| 3445 |
|
| 3446 |
+
[^18]: By using, for example, the library functions ([[headers]])
|
| 3447 |
`std::memcpy` or `std::memmove`.
|
| 3448 |
|
| 3449 |
+
[^19]: By using, for example, the library functions ([[headers]])
|
| 3450 |
`std::memcpy` or `std::memmove`.
|
| 3451 |
|
| 3452 |
+
[^20]: The intent is that the memory model of C++is compatible with that
|
| 3453 |
of ISO/IEC 9899 Programming Language C.
|
| 3454 |
|
| 3455 |
+
[^21]: The size and layout of an instance of an incompletely-defined
|
| 3456 |
object type is unknown.
|
| 3457 |
|
| 3458 |
+
[^22]: that is, large enough to contain any value in the range of
|
| 3459 |
`INT_MIN` and `INT_MAX`, as defined in the header `<climits>`.
|
| 3460 |
|
| 3461 |
+
[^23]: See [[dcl.type.simple]] regarding the correspondence between
|
| 3462 |
types and the sequences of *type-specifier*s that designate them.
|
| 3463 |
|
| 3464 |
+
[^24]: This implies that unsigned arithmetic does not overflow because a
|
| 3465 |
result that cannot be represented by the resulting unsigned integer
|
| 3466 |
type is reduced modulo the number that is one greater than the
|
| 3467 |
largest value that can be represented by the resulting unsigned
|
| 3468 |
integer type.
|
| 3469 |
|
| 3470 |
+
[^25]: Using a `bool` value in ways described by this International
|
| 3471 |
Standard as “undefined,” such as by examining the value of an
|
| 3472 |
uninitialized automatic object, might cause it to behave as if it is
|
| 3473 |
neither `true` nor `false`.
|
| 3474 |
|
| 3475 |
+
[^26]: Therefore, enumerations ([[dcl.enum]]) are not integral;
|
| 3476 |
however, enumerations can be promoted to integral types as specified
|
| 3477 |
in [[conv.prom]].
|
| 3478 |
|
| 3479 |
+
[^27]: A positional representation for integers that uses the binary
|
| 3480 |
digits 0 and 1, in which the values represented by successive bits
|
| 3481 |
are additive, begin with 1, and are multiplied by successive
|
| 3482 |
integral power of 2, except perhaps for the bit with the highest
|
| 3483 |
position. (Adapted from the *American National Dictionary for
|
| 3484 |
Information Processing Systems*.)
|
| 3485 |
|
| 3486 |
+
[^28]: Static class members are objects or functions, and pointers to
|
| 3487 |
them are ordinary pointers to objects or functions.
|
| 3488 |
|
| 3489 |
+
[^29]: The same representation and alignment requirements are meant to
|
| 3490 |
imply interchangeability as arguments to functions, return values
|
| 3491 |
from functions, and non-static data members of unions.
|
| 3492 |
|
| 3493 |
+
[^30]: The intent of this list is to specify those circumstances in
|
| 3494 |
which an object may or may not be aliased.
|