|
4 | 4 | \gramSec[gram.basic]{Basic concepts}
|
5 | 5 |
|
6 | 6 | \pnum
|
7 |
| -\begin{note} This Clause presents the basic concepts of the \Cpp language. |
| 7 | +\begin{note} This Clause presents the basic concepts of the \Cpp{} language. |
8 | 8 | It explains the difference between an object and a
|
9 | 9 | name and how they relate to the value categories for expressions.
|
10 | 10 | It introduces the concepts of a
|
11 |
| -declaration and a definition and presents \Cpp's |
| 11 | +declaration and a definition and presents \Cpp{}'s |
12 | 12 | notion of type, scope, linkage, and
|
13 | 13 | storage duration. The mechanisms for starting and
|
14 | 14 | terminating a program are discussed. Finally, this Clause presents the
|
|
215 | 215 | \pnum
|
216 | 216 | \begin{note}
|
217 | 217 | \indextext{implementation-generated}%
|
218 |
| -In some circumstances, \Cpp implementations implicitly define the |
| 218 | +In some circumstances, \Cpp{} implementations implicitly define the |
219 | 219 | default constructor\iref{class.ctor},
|
220 | 220 | copy constructor\iref{class.copy},
|
221 | 221 | move constructor\iref{class.copy},
|
|
776 | 776 | \item for a declaration of the form
|
777 | 777 |
|
778 | 778 | \begin{ncbnf}
|
779 |
| -class-key attribute-specifier-seq\opt identifier \terminal{;} |
| 779 | +class-key attribute-specifier-seq\opt{} identifier \terminal{;} |
780 | 780 | \end{ncbnf}
|
781 | 781 |
|
782 | 782 | the \grammarterm{identifier} is declared to be a
|
|
1775 | 1775 | \grammarterm{qualified-id} of the form:
|
1776 | 1776 |
|
1777 | 1777 | \begin{ncbnf}
|
1778 |
| -nested-name-specifier\opt class-name \terminal{::} \terminal{\tilde} class-name |
| 1778 | +nested-name-specifier\opt{} class-name \terminal{::} \terminal{\~} class-name |
1779 | 1779 | \end{ncbnf}
|
1780 | 1780 |
|
1781 | 1781 | the second \grammarterm{class-name} is looked up in the same scope as the
|
|
2135 | 2135 | following form:
|
2136 | 2136 |
|
2137 | 2137 | \begin{ncbnf}
|
2138 |
| -class-key attribute-specifier-seq\opt identifier \terminal{;} |
| 2138 | +class-key attribute-specifier-seq\opt{} identifier \terminal{;} |
2139 | 2139 | \end{ncbnf}
|
2140 | 2140 |
|
2141 | 2141 | the \grammarterm{identifier} is looked up according
|
|
2150 | 2150 | form:
|
2151 | 2151 |
|
2152 | 2152 | \begin{ncbnf}
|
2153 |
| -class-key attribute-specifier-seq\opt identifier \terminal{;} |
| 2153 | +class-key attribute-specifier-seq\opt{} identifier \terminal{;} |
2154 | 2154 | \end{ncbnf}
|
2155 | 2155 |
|
2156 | 2156 | the \grammarterm{elaborated-type-specifier} is a declaration that
|
|
2316 | 2316 |
|
2317 | 2317 | \begin{bnf}
|
2318 | 2318 | \nontermdef{translation-unit}\br
|
2319 |
| - declaration-seq\opt |
| 2319 | + declaration-seq\opt{} |
2320 | 2320 | \end{bnf}
|
2321 | 2321 |
|
2322 | 2322 | \pnum
|
|
2540 | 2540 | identity does not require a diagnostic.
|
2541 | 2541 |
|
2542 | 2542 | \pnum
|
2543 |
| -\begin{note} Linkage to non-\Cpp declarations can be achieved using a |
| 2543 | +\begin{note} Linkage to non-\Cpp{} declarations can be achieved using a |
2544 | 2544 | \grammarterm{linkage-specification}\iref{dcl.link}. \end{note}%
|
2545 | 2545 | \indextext{linkage|)}
|
2546 | 2546 |
|
|
2550 | 2550 |
|
2551 | 2551 | \pnum
|
2552 | 2552 | \indextext{memory model|(}%
|
2553 |
| -The fundamental storage unit in the \Cpp memory model is the |
| 2553 | +The fundamental storage unit in the \Cpp{} memory model is the |
2554 | 2554 | \defn{byte}.
|
2555 | 2555 | A byte is at least large enough to contain any member of the basic
|
2556 | 2556 | \indextext{character set!basic execution}%
|
|
2562 | 2562 | the number of which is \impldef{bits in a byte}. The least
|
2563 | 2563 | significant bit is called the \defn{low-order bit}; the most
|
2564 | 2564 | significant bit is called the \defn{high-order bit}. The memory
|
2565 |
| -available to a \Cpp program consists of one or more sequences of |
| 2565 | +available to a \Cpp{} program consists of one or more sequences of |
2566 | 2566 | contiguous bytes. Every byte has a unique address.
|
2567 | 2567 |
|
2568 | 2568 | \pnum
|
|
2614 | 2614 |
|
2615 | 2615 | \pnum
|
2616 | 2616 | \indextext{object model|(}%
|
2617 |
| -The constructs in a \Cpp program create, destroy, refer to, access, and |
| 2617 | +The constructs in a \Cpp{} program create, destroy, refer to, access, and |
2618 | 2618 | manipulate objects.
|
2619 | 2619 | An \defn{object} is created
|
2620 | 2620 | by a definition\iref{basic.def},
|
|
2800 | 2800 |
|
2801 | 2801 | \pnum
|
2802 | 2802 | \begin{note}
|
2803 |
| -\Cpp provides a variety of fundamental types and several ways of composing |
| 2803 | +\Cpp{} provides a variety of fundamental types and several ways of composing |
2804 | 2804 | new types from existing types\iref{basic.types}.
|
2805 | 2805 | \end{note}%
|
2806 | 2806 | \indextext{object model|)}
|
|
2877 | 2877 | For an object under construction or destruction, see~\ref{class.cdtor}.
|
2878 | 2878 | Otherwise, such
|
2879 | 2879 | a pointer refers to allocated
|
2880 |
| -storage\iref{basic.stc.dynamic.deallocation}, and using the pointer as |
| 2880 | +storage\iref{basic.stc.dynamic.allocation}, and using the pointer as |
2881 | 2881 | if the pointer were of type \tcode{void*}, is
|
2882 | 2882 | well-defined. Indirection through such a pointer is permitted but the resulting lvalue may only be used in
|
2883 | 2883 | limited ways, as described below. The
|
|
2943 | 2943 | For an object under construction or destruction, see~\ref{class.cdtor}.
|
2944 | 2944 | Otherwise, such
|
2945 | 2945 | a glvalue refers to
|
2946 |
| -allocated storage\iref{basic.stc.dynamic.deallocation}, and using the |
| 2946 | +allocated storage\iref{basic.stc.dynamic.allocation}, and using the |
2947 | 2947 | properties of the glvalue that do not depend on its value is
|
2948 | 2948 | well-defined. The program has undefined behavior if:
|
2949 | 2949 | \begin{itemize}
|
|
3181 | 3181 | \indextext{\idxcode{new}}%
|
3182 | 3182 | \grammarterm{new-expression}{s}\iref{expr.new}, and destroyed using
|
3183 | 3183 | \indextext{\idxcode{delete}}%
|
3184 |
| -\grammarterm{delete-expression}{s}\iref{expr.delete}. A \Cpp implementation |
| 3184 | +\grammarterm{delete-expression}{s}\iref{expr.delete}. A \Cpp{} implementation |
3185 | 3185 | provides access to, and management of, dynamic storage via the global
|
3186 | 3186 | \defn{allocation functions} \tcode{operator new} and \tcode{operator
|
3187 | 3187 | new[]} and the global \defn{deallocation functions} \tcode{operator
|
|
3194 | 3194 | \pnum
|
3195 | 3195 | The library provides default definitions for the global allocation and
|
3196 | 3196 | deallocation functions. Some global allocation and deallocation
|
3197 |
| -functions are replaceable\iref{new.delete}. A \Cpp program shall |
| 3197 | +functions are replaceable\iref{new.delete}. A \Cpp{} program shall |
3198 | 3198 | provide at most one definition of a replaceable allocation or
|
3199 | 3199 | deallocation function. Any such function definition replaces the default
|
3200 | 3200 | version provided in the library\iref{replacement.functions}. The
|
|
3203 | 3203 | program.
|
3204 | 3204 |
|
3205 | 3205 | \begin{codeblock}
|
3206 |
| -void* operator new(std::size_t); |
3207 |
| -void* operator new(std::size_t, std::align_val_t); |
| 3206 | +[[nodiscard]] void* operator new(std::size_t); |
| 3207 | +[[nodiscard]] void* operator new(std::size_t, std::align_val_t); |
3208 | 3208 |
|
3209 | 3209 | void operator delete(void*) noexcept;
|
3210 | 3210 | void operator delete(void*, std::size_t) noexcept;
|
3211 | 3211 | void operator delete(void*, std::align_val_t) noexcept;
|
3212 | 3212 | void operator delete(void*, std::size_t, std::align_val_t) noexcept;
|
3213 | 3213 |
|
3214 |
| -void* operator new[](std::size_t); |
3215 |
| -void* operator new[](std::size_t, std::align_val_t); |
| 3214 | +[[nodiscard]] void* operator new[](std::size_t); |
| 3215 | +[[nodiscard]] void* operator new[](std::size_t, std::align_val_t); |
3216 | 3216 |
|
3217 | 3217 | void operator delete[](void*) noexcept;
|
3218 | 3218 | void operator delete[](void*, std::size_t) noexcept;
|
|
3240 | 3240 | class\iref{class.free}.
|
3241 | 3241 |
|
3242 | 3242 | \pnum
|
3243 |
| -Any allocation and/or deallocation functions defined in a \Cpp program, |
| 3243 | +Any allocation and/or deallocation functions defined in a \Cpp{} program, |
3244 | 3244 | including the default versions in the library, shall conform to the
|
3245 | 3245 | semantics specified in~\ref{basic.stc.dynamic.allocation}
|
3246 | 3246 | and~\ref{basic.stc.dynamic.deallocation}.
|
|
3288 | 3288 | returned as a request for zero size is undefined.\footnote{The intent is
|
3289 | 3289 | to have \tcode{operator new()} implementable by
|
3290 | 3290 | calling \tcode{std::malloc()} or \tcode{std::calloc()}, so the rules are
|
3291 |
| -substantially the same. \Cpp differs from C in requiring a zero request |
| 3291 | +substantially the same. \Cpp{} differs from C in requiring a zero request |
3292 | 3292 | to return a non-null pointer.}
|
3293 | 3293 |
|
3294 | 3294 | \pnum
|
|
3311 | 3311 | A global allocation function is only called as the result of a new
|
3312 | 3312 | expression\iref{expr.new}, or called directly using the function call
|
3313 | 3313 | syntax\iref{expr.call}, or called indirectly through calls to the
|
3314 |
| -functions in the \Cpp standard library. \begin{note} In particular, a |
| 3314 | +functions in the \Cpp{} standard library. \begin{note} In particular, a |
3315 | 3315 | global allocation function is not called to allocate storage for objects
|
3316 | 3316 | with static storage duration\iref{basic.stc.static}, for objects or references
|
3317 | 3317 | with thread storage duration\iref{basic.stc.thread}, for objects of
|
|
3394 | 3394 | A pointer value is a \defn{safely-derived pointer} to a dynamic object only if it
|
3395 | 3395 | has an object pointer type and it is one of the following:
|
3396 | 3396 | \begin{itemize}
|
3397 |
| -\item the value returned by a call to the \Cpp standard library implementation of |
| 3397 | +\item the value returned by a call to the \Cpp{} standard library implementation of |
3398 | 3398 | \tcode{::operator new(std::\brk{}size_t)} or
|
3399 | 3399 | \tcode{::operator new(std::size_t, std::align_val_t)}%
|
3400 | 3400 | ;\footnote{This subclause does not impose restrictions
|
3401 | 3401 | on indirection through pointers to memory not allocated by \tcode{::operator new}. This
|
3402 |
| -maintains the ability of many \Cpp implementations to use binary libraries and |
| 3402 | +maintains the ability of many \Cpp{} implementations to use binary libraries and |
3403 | 3403 | components written in other languages. In particular, this applies to C binaries,
|
3404 | 3404 | because indirection through pointers to memory allocated by \tcode{std::malloc} is not restricted.}
|
3405 | 3405 |
|
|
3636 | 3636 | a set of bits in the object representation that determines a
|
3637 | 3637 | \defn{value}, which is one discrete element of an
|
3638 | 3638 | \impldef{values of a trivially copyable type} set of values.\footnote{The
|
3639 |
| -intent is that the memory model of \Cpp is compatible |
| 3639 | +intent is that the memory model of \Cpp{} is compatible |
3640 | 3640 | with that of ISO/IEC 9899 Programming Language C.}
|
3641 | 3641 |
|
3642 | 3642 | \pnum
|
|
3751 | 3751 | within a constant expression.
|
3752 | 3752 | It is not a guarantee that it is possible to create such an object,
|
3753 | 3753 | nor is it a guarantee that any object of that type
|
3754 |
| -will usable in a constant expression. |
| 3754 | +will be usable in a constant expression. |
3755 | 3755 | \end{note}
|
3756 | 3756 |
|
3757 | 3757 | \pnum
|
|
4556 | 4556 | If \placeholder{A} and \placeholder{B} would not otherwise be sequenced then they are
|
4557 | 4557 | indeterminately sequenced.
|
4558 | 4558 | \end{note}
|
4559 |
| -Several contexts in \Cpp cause evaluation of a function call, even |
| 4559 | +Several contexts in \Cpp{} cause evaluation of a function call, even |
4560 | 4560 | though no corresponding function call syntax appears in the translation
|
4561 | 4561 | unit.
|
4562 | 4562 | \begin{example}
|
|
4596 | 4596 | with automatic or thread storage duration\iref{basic.stc} is associated with
|
4597 | 4597 | one specific thread, and can be accessed by a different thread only indirectly
|
4598 | 4598 | through a pointer or reference\iref{basic.compound}.} Under a hosted
|
4599 |
| -implementation, a \Cpp program can have more than one thread running |
| 4599 | +implementation, a \Cpp{} program can have more than one thread running |
4600 | 4600 | concurrently. The execution of each thread proceeds as defined by the remainder
|
4601 | 4601 | of this document. The execution of the entire program consists of an execution
|
4602 | 4602 | of all of its threads. \begin{note} Usually the execution can be viewed as an
|
|
4878 | 4878 | \begin{note} The four preceding coherence requirements effectively disallow
|
4879 | 4879 | compiler reordering of atomic operations to a single object, even if both
|
4880 | 4880 | operations are relaxed loads. This effectively makes the cache coherence
|
4881 |
| -guarantee provided by most hardware available to \Cpp atomic operations. |
| 4881 | +guarantee provided by most hardware available to \Cpp{} atomic operations. |
4882 | 4882 | \end{note}
|
4883 | 4883 |
|
4884 | 4884 | \pnum
|
|
4902 | 4902 | except for the special case for signal handlers described below.
|
4903 | 4903 | Any such data race results in undefined
|
4904 | 4904 | behavior. \begin{note} It can be shown that programs that correctly use mutexes
|
4905 |
| -and \tcode{memory_order_seq_cst} operations to prevent all data races and use no |
| 4905 | +and \tcode{memory_order::seq_cst} operations to prevent all data races and use no |
4906 | 4906 | other synchronization operations behave as if the operations executed by their
|
4907 | 4907 | constituent threads were simply interleaved, with each
|
4908 | 4908 | \indextext{value computation}%
|
|
4942 | 4942 |
|
4943 | 4943 | \pnum
|
4944 | 4944 | \begin{note} Transformations that introduce a speculative read of a potentially
|
4945 |
| -shared memory location may not preserve the semantics of the \Cpp program as |
| 4945 | +shared memory location may not preserve the semantics of the \Cpp{} program as |
4946 | 4946 | defined in this document, since they potentially introduce a data race. However,
|
4947 | 4947 | they are typically valid in the context of an optimizing compiler that targets a
|
4948 | 4948 | specific machine with well-defined semantics for data races. They would be
|
|
5174 | 5174 |
|
5175 | 5175 | \pnum
|
5176 | 5176 | An implementation shall not predefine the \tcode{main} function. This
|
5177 |
| -function shall not be overloaded. Its type shall have \Cpp language linkage |
| 5177 | +function shall not be overloaded. Its type shall have \Cpp{} language linkage |
5178 | 5178 | and it shall have a declared return type of type
|
5179 | 5179 | \tcode{int}, but otherwise its type is \impldef{parameters to \tcode{main}}.
|
5180 | 5180 | \indextext{\idxcode{main} function!implementation-defined parameters to}%
|
|
5198 | 5198 | \tcode{argv[0]} through \tcode{argv[argc-1]} as pointers to the initial
|
5199 | 5199 | characters of null-terminated multibyte strings (\ntmbs{}s)\iref{multibyte.strings}
|
5200 | 5200 | and \tcode{argv[0]} shall be the pointer to
|
5201 |
| -the initial character of a \ntmbs that represents the name used to |
| 5201 | +the initial character of a \ntmbs{} that represents the name used to |
5202 | 5202 | invoke the program or \tcode{""}. The value of \tcode{argc} shall be
|
5203 | 5203 | non-negative. The value of \tcode{argv[argc]} shall be 0. \begin{note} It
|
5204 | 5204 | is recommended that any further (optional) parameters be added after
|
|
5548 | 5548 | \indexlibrary{\idxcode{abort}}%
|
5549 | 5549 | \indextext{termination!program}%
|
5550 | 5550 | Calling the function \tcode{std::abort()} declared in
|
5551 |
| -\indextext{\idxhdr{cstdlib}}% |
| 5551 | +\indexhdr{cstdlib}% |
5552 | 5552 | \tcode{<cstdlib>} terminates the program without executing any destructors
|
5553 | 5553 | and without calling
|
5554 | 5554 | the functions passed to \tcode{std::atexit()} or \tcode{std::at_quick_exit()}.%
|
|
0 commit comments