mirror of
https://github.com/isocpp/CppCoreGuidelines.git
synced 2024-03-22 13:30:58 +08:00
Closes #1355
This commit is contained in:
parent
fcba85fb48
commit
5d2c09aa48
|
@ -8938,7 +8938,7 @@ Here, we ignore such cases.
|
||||||
* [R.11: Avoid calling `new` and `delete` explicitly](#Rr-newdelete)
|
* [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.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.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)
|
* [R.15: Always overload matched allocation/deallocation pairs](#Rr-pair)
|
||||||
|
|
||||||
* <a name="Rr-summary-smartptrs"></a>Smart pointer rule summary:
|
* <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?)
|
* 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
|
##### Reason
|
||||||
|
|
||||||
An array decays to a pointer, thereby losing its size, opening the opportunity for range errors.
|
An array decays to a pointer, thereby losing its size, opening the opportunity for range errors.
|
||||||
|
Use `span` to preserve size information.
|
||||||
|
|
||||||
##### Example
|
##### Example
|
||||||
|
|
||||||
??? what do we recommend: f(int*[]) or f(int**) ???
|
void f(int[]); // not recommended
|
||||||
|
|
||||||
|
void f(int*); // not recommended for multiple objects (a pointer should point to a single object, do not subscript)
|
||||||
|
|
||||||
**Alternative**: Use `span` to preserve size information.
|
void f(gsl::span<int>); // good, recommended
|
||||||
|
|
||||||
##### Enforcement
|
##### Enforcement
|
||||||
|
|
||||||
Flag `[]` parameters.
|
Flag `[]` parameters. Use `span` instead.
|
||||||
|
|
||||||
### <a name="Rr-pair"></a>R.15: Always overload matched allocation/deallocation pairs
|
### <a name="Rr-pair"></a>R.15: Always overload matched allocation/deallocation pairs
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user