@ -14378,7 +14378,7 @@ but it can only identify races seen in a given execution.
##### Enforcement
It is up to an application builder to choose which support tools are valuable for a particular applications.
It is up to an application builder to choose which support tools are valuable for a particular application.
## <aname="SScp-con"></a>CP.con: Concurrency
@ -15626,7 +15626,7 @@ The rules are designed to help avoid several kinds of errors:
* Type violations (e.g., misuse of `union`s and casts)
* Resource leaks (including memory leaks)
* Bounds errors
* Lifetime errors (e.g., accessing an object after is has been `delete`d)
* Lifetime errors (e.g., accessing an object after it has been `delete`d)
* Complexity errors (logical errors made likely by overly complex expression of ideas)
* Interface errors (e.g., an unexpected value is passed through an interface)
@ -15684,7 +15684,7 @@ To make error handling systematic, robust, and non-repetitive.
// ...
}
Here, `vector` and `string`s constructors might not be able to allocate sufficient memory for their elements, `vector`s constructor might not be able copy the `Thing`s in its initializer list, and `File_handle` might not be able to open the required file.
Here, `vector` and `string`s constructors might not be able to allocate sufficient memory for their elements, `vector`s constructor might not be able to copy the `Thing`s in its initializer list, and `File_handle` might not be able to open the required file.
In each case, they throw an exception for `use()`'s caller to handle.
If `use()` could handle the failure to construct `bar` it can take control using `try`/`catch`.
In either case, `Foo`'s constructor correctly destroys constructed members before passing control to whatever tried to create a `Foo`.
@ -15799,7 +15799,7 @@ Not all member functions can be called.
The class invariant - here stated as a comment - is established by the constructors.
`new` throws if it cannot allocate the required memory.
The operators, notably the subscript operator, relies on the invariant.
The operators, notably the subscript operator, rely on the invariant.
**See also**: [If a constructor cannot construct a valid object, throw an exception](#Rc-throw)
@ -16634,7 +16634,7 @@ Flag all "hiding handlers".
You can't have a race condition on a constant.
It is easier to reason about a program when many of the objects cannot change their values.
Interfaces that promises "no change" of objects passed as arguments greatly increase readability.
Interfaces that promise "no change" of objects passed as arguments greatly increase readability.
Constant rule summary:
@ -20703,7 +20703,7 @@ and errors (when we didn't deal correctly with semi-constructed objects consiste
if (!picture.Init()) {
puts("Error, invalid picture");
}
// now have a invalid picture object instance.
// now have an invalid picture object instance.
##### Example, good
@ -20936,7 +20936,7 @@ A textbook for beginners and relative novices.
* Stroustrup, Sutter, and Dos Reis: [A brief introduction to C++'s model for type- and resource-safety](http://www.stroustrup.com/resource-model.pdf). A paper with lots of examples.
@ -21206,8 +21206,8 @@ Use `not_null<zstring>` for C-style strings that cannot be `nullptr`. ??? Do we
* `shared_ptr<T>` // shared ownership: `std::shared_ptr<T>` (a counted pointer)
* `stack_array<T>` // A stack-allocated array. The number of elements are determined at construction and fixed thereafter. The elements are mutable unless `T` is a `const` type.
* `dyn_array<T>` // ??? needed ??? A heap-allocated array. The number of elements are determined at construction and fixed thereafter.
* `stack_array<T>` // A stack-allocated array. The number of elements is determined at construction and fixed thereafter. The elements are mutable unless `T` is a `const` type.
* `dyn_array<T>` // ??? needed ??? A heap-allocated array. The number of elements is determined at construction and fixed thereafter.
The elements are mutable unless `T` is a `const` type. Basically a `span` that allocates and owns its elements.
@ -22678,7 +22678,7 @@ More information on many topics about C++ can be found on the [Standard C++ Foun
* *constructor*: an operation that initializes ("constructs") an object.
Typically a constructor establishes an invariant and often acquires resources needed for an object to be used (which are then typically released by a destructor).
* *container*: an object that holds elements (other objects).
* *copy*: an operation that makes two object have values that compare equal. See also move.
* *copy*: an operation that makes two objects have values that compare equal. See also move.
* *correctness*: a program or a piece of a program is correct if it meets its specification.
Unfortunately, a specification can be incomplete or inconsistent, or can fail to meet users' reasonable expectations.
Thus, to produce acceptable code, we sometimes have to do more than just follow the formal specification.
@ -22721,7 +22721,7 @@ More information on many topics about C++ can be found on the [Standard C++ Foun
* *iteration*: the act of repeatedly executing a piece of code; see recursion.
* *iterator*: an object that identifies an element of a sequence.
* *ISO*: International Organization for Standardization. The C++ language is an ISO standard, ISO/IEC 14882. More information at [iso.org](http://iso.org).
* *library*: a collection of types, functions, classes, etc. implementing a set of facilities (abstractions) meant to be potentially used as part of more that one program.
* *library*: a collection of types, functions, classes, etc. implementing a set of facilities (abstractions) meant to be potentially used as part of more than one program.
* *lifetime*: the time from the initialization of an object until it becomes unusable (goes out of scope, is deleted, or the program terminates).
* *linker*: a program that combines object code files and libraries into an executable program.
* *literal*: a notation that directly specifies a value, such as 12 specifying the integer value "twelve."
@ -22761,7 +22761,7 @@ In particular, an object of a regular type can be copied and the result of a cop
* *rounding*: conversion of a value to the mathematically nearest value of a less precise type.
* *RTTI*: Run-Time Type Information. ???
* *scope*: the region of program text (source code) in which a name can be referred to.
* *semiregular*: a concrete type that is copyable (including movable) and default-constructible (see `std::semiregular` concept). The result of a copy is an independent object with the same value as the original. A semiregular type behaves roughly like an built-in type like `int`, but possibly without a `==` operator. See also *regular type*.
* *semiregular*: a concrete type that is copyable (including movable) and default-constructible (see `std::semiregular` concept). The result of a copy is an independent object with the same value as the original. A semiregular type behaves roughly like a built-in type like `int`, but possibly without a `==` operator. See also *regular type*.
* *sequence*: elements that can be visited in a linear order.
* *software*: a collection of pieces of code and associated data; often used interchangeably with program.
* *source code*: code as produced by a programmer and (in principle) readable by other programmers.