This commit is contained in:
hsutter 2019-03-07 12:00:41 -08:00
parent fcba85fb48
commit 5d2c09aa48

View File

@ -8938,7 +8938,7 @@ Here, we ignore such cases.
* [R.11: Avoid calling `new` and `delete` explicitly](#Rr-newdelete)
* [R.12: Immediately give the result of an explicit resource allocation to a manager object](#Rr-immediate-alloc)
* [R.13: Perform at most one explicit resource allocation in a single expression statement](#Rr-single-alloc)
* [R.14: ??? array vs. pointer parameter](#Rr-ap)
* [R.14: Avoid `[]` parameters, prefer `span`](#Rr-ap)
* [R.15: Always overload matched allocation/deallocation pairs](#Rr-pair)
* <a name="Rr-summary-smartptrs"></a>Smart pointer rule summary:
@ -9379,21 +9379,24 @@ Write your own factory wrapper if there is not one already.
* Flag expressions with multiple explicit resource allocations (problem: how many direct resource allocations can we recognize?)
### <a name="Rr-ap"></a>R.14: ??? array vs. pointer parameter
### <a name="Rr-ap"></a>R.14: Avoid `[]` parameters, prefer `span`
##### Reason
An array decays to a pointer, thereby losing its size, opening the opportunity for range errors.
Use `span` to preserve size information.
##### Example
??? what do we recommend: f(int*[]) or f(int**) ???
void f(int[]); // not recommended
**Alternative**: Use `span` to preserve size information.
void f(int*); // not recommended for multiple objects (a pointer should point to a single object, do not subscript)
void f(gsl::span<int>); // good, recommended
##### Enforcement
Flag `[]` parameters.
Flag `[]` parameters. Use `span` instead.
### <a name="Rr-pair"></a>R.15: Always overload matched allocation/deallocation pairs